rust-lang / rust-lang/rfcs

__attribute__((sentinel)) for C FFI variadic functions

Open
#1,217 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

T-compiler T-dev-tools T-lang
Dominant language
Markdown
Stars
6.6k
Forks
1.7k
Avg merge
16h 14m
Merged PRs (30d)
1

Description

__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.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reviewing the requested Rust support and the linked GCC sentinel attribute documentation. Determine how the attribute should be represented for foreign variadic functions, which argument positions are valid, and how call-site diagnostics should behave; done means the semantics and implementation scope are defined well enough for an RFC or compiler change.

Written by the indexing model from the issue text.

Assessment

Tech stack
c, rust
Domain
compilers
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.