Skip to content

__attribute__((sentinel)) for C FFI variadic functions #1217

Open
@tomjakubowski

Description

@tomjakubowski

__attribute__((sentinel)) or __attribute__((sentinel(N))) is a GNU C extension (also supported by clang) that marks variadic functions as requiring a sentinel NULL value in the last (or (N+1)th-to-last) argument slot. The compiler checks uses of this function and emits a warning (-Wformat) if the NULL sentinel value is not present in the expected location in the parameter list.

https://gcc.gnu.org/onlinedocs/gcc-4.0.4/gcc/Function-Attributes.html#index-g_t_0040code_007bsentinel_007d-function-attribute-1760

It would be nice to be able to mark foreign variadic functions in Rust the same way, such that the compiler checks that a sentinel NULL appears in the proper position at call sites for these functions. GCC considers any 0-initialized pointer type to be NULL in this context.

Metadata

Metadata

Assignees

No one assigned

    Labels

    T-compilerRelevant to the compiler team, which will review and decide on the RFC.T-dev-toolsRelevant to the development tools team, which will review and decide on the RFC.T-langRelevant to the language team, which will review and decide on the RFC.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions