https://github.com/to268 created https://github.com/llvm/llvm-project/pull/196088
The documentation of the sentinel attribute was missing, this PR documents the behavior of the sentinel attribute. >From 5e9fccdc38bd681c064859ea8898c104a2bd5b2e Mon Sep 17 00:00:00 2001 From: Tony Guillot <[email protected]> Date: Wed, 6 May 2026 16:48:40 +0200 Subject: [PATCH] Documented sentinel attribute --- clang/include/clang/Basic/Attr.td | 2 +- clang/include/clang/Basic/AttrDocs.td | 28 +++++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/clang/include/clang/Basic/Attr.td b/clang/include/clang/Basic/Attr.td index 04b7f420e1b32..3eeb58efa7e3b 100644 --- a/clang/include/clang/Basic/Attr.td +++ b/clang/include/clang/Basic/Attr.td @@ -3415,7 +3415,7 @@ def Sentinel : InheritableAttr { let Args = [DefaultIntArgument<"Sentinel", 0>, DefaultIntArgument<"NullPos", 0>]; // let Subjects = SubjectList<[Function, ObjCMethod, Block, Var]>; - let Documentation = [Undocumented]; + let Documentation = [SentinelDocs]; } def StdCall : DeclOrTypeAttr { diff --git a/clang/include/clang/Basic/AttrDocs.td b/clang/include/clang/Basic/AttrDocs.td index 67aef81dd3a81..d10b9539999e1 100644 --- a/clang/include/clang/Basic/AttrDocs.td +++ b/clang/include/clang/Basic/AttrDocs.td @@ -10000,3 +10000,31 @@ different languages to coexist on the same call stack while each interpreting exceptions according to their own rules. }]; } + +def SentinelDocs : Documentation { + let Category = DocCatFunction; + let Content = [{ +The ``sentinel`` attribute can only be applied to variadic functions to +diagnose each function call that do not pass a sentinel value at the end of the +argument list. It checks if a null pointer constant exists at the end of the +argument list by default, or at the (N+1)th position starting from the end when +an argument is provided. + +.. code-block:: c + + #include <stddef.h> + + void foo(const char*, ...) __attribute__((sentinel)); + void bar(int, ...) __attribute__((sentinel(1))); + + void example() { + foo("Example", (void*)0); + foo("Another", "example", NULL); + foo("Missing", "sentinel"); // Not OK + + bar(1, 2, NULL, 3); // OK: sentinel value at the 2nd to last positon + bar(1, 2, 3, nullptr, 4); // OK: `nullptr` is valid in C23 + bar(1, 2, 3, 4, NULL); // Not OK + } + }]; +} _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
