https://github.com/AaronBallman updated https://github.com/llvm/llvm-project/pull/203303
>From 3492bf5ce199003ec7014e2fb965bd60c54de279 Mon Sep 17 00:00:00 2001 From: Aaron Ballman <[email protected]> Date: Thu, 11 Jun 2026 11:20:18 -0400 Subject: [PATCH 1/3] Document the [[clang::annotate]] attribute The new documentation mirrors the existing docs for annotate_type. --- clang/include/clang/Basic/Attr.td | 2 +- clang/include/clang/Basic/AttrDocs.td | 27 +++++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/clang/include/clang/Basic/Attr.td b/clang/include/clang/Basic/Attr.td index 7f7e9489782a7..d494a00daed38 100644 --- a/clang/include/clang/Basic/Attr.td +++ b/clang/include/clang/Basic/Attr.td @@ -1039,7 +1039,7 @@ def Annotate : InheritableParamOrStmtAttr { }]; let PragmaAttributeSupport = 1; let AcceptsExprPack = 1; - let Documentation = [Undocumented]; + let Documentation = [AnnotateDocs]; } def AnnotateType : TypeAttr { diff --git a/clang/include/clang/Basic/AttrDocs.td b/clang/include/clang/Basic/AttrDocs.td index dab778d4047aa..28b1a2fe05989 100644 --- a/clang/include/clang/Basic/AttrDocs.td +++ b/clang/include/clang/Basic/AttrDocs.td @@ -9145,6 +9145,33 @@ point." }]; } +def AnnotateDocs : Documentation { + let Category = DocCatDecl; + let Content = [{ +This attribute is used to add annotations to declarations or statements, +typically for use by static analysis tools that are not integrated into the +core Clang compiler (e.g., Clang-Tidy checks or out-of-tree Clang-based tools). +It is a counterpart to the `annotate_type` attribute, which serves the same +purpose, but for types. + +The attribute takes a mandatory string literal argument specifying the +annotation category and an arbitrary number of optional arguments that provide +additional information specific to the annotation category. The optional +arguments must be constant expressions of arbitrary type. + +For example: + +.. code-block:: c++ + + [[clang::annotate("category1", "foo", 1)]] void func(int val [[clang::annotate("category2")]]) { + [[clang::annotate("category3")]] if (val) { + + } + } + + }]; +} + def AnnotateTypeDocs : Documentation { let Category = DocCatType; let Heading = "annotate_type"; >From 214d0be053e17736a9ff3762c8b9a27b1a008e1f Mon Sep 17 00:00:00 2001 From: Aaron Ballman <[email protected]> Date: Thu, 11 Jun 2026 14:06:01 -0400 Subject: [PATCH 2/3] Fix test after merge --- clang/test/AST/undocumented-attrs.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/clang/test/AST/undocumented-attrs.cpp b/clang/test/AST/undocumented-attrs.cpp index c7a2c74631ea2..36fed58c540e1 100644 --- a/clang/test/AST/undocumented-attrs.cpp +++ b/clang/test/AST/undocumented-attrs.cpp @@ -11,7 +11,6 @@ CHECK-NEXT: AcquiredBefore CHECK-NEXT: Alias CHECK-NEXT: Aligned CHECK-NEXT: AnalyzerNoReturn -CHECK-NEXT: Annotate CHECK-NEXT: ArcWeakrefUnavailable CHECK-NEXT: AvailableOnlyInDefaultEvalMethod CHECK-NEXT: Blocks @@ -91,4 +90,4 @@ CHECK-NEXT: Visibility CHECK-NEXT: WeakImport CHECK-NEXT: WeakRef CHECK-NEXT: WorkGroupSizeHint -CHECK-NEXT: Total: 85 +CHECK-NEXT: Total: 84 >From 0ea1195be8b73eabce5e6572cc4fe7413e7ac8a1 Mon Sep 17 00:00:00 2001 From: Aaron Ballman <[email protected]> Date: Tue, 23 Jun 2026 08:09:37 -0400 Subject: [PATCH 3/3] Update clang/include/clang/Basic/AttrDocs.td Co-authored-by: Erich Keane <[email protected]> --- clang/include/clang/Basic/AttrDocs.td | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clang/include/clang/Basic/AttrDocs.td b/clang/include/clang/Basic/AttrDocs.td index 28b1a2fe05989..f381a6e063749 100644 --- a/clang/include/clang/Basic/AttrDocs.td +++ b/clang/include/clang/Basic/AttrDocs.td @@ -9148,7 +9148,7 @@ point." def AnnotateDocs : Documentation { let Category = DocCatDecl; let Content = [{ -This attribute is used to add annotations to declarations or statements, +The `annotate` attribute is used to add annotations to declarations or statements, typically for use by static analysis tools that are not integrated into the core Clang compiler (e.g., Clang-Tidy checks or out-of-tree Clang-based tools). It is a counterpart to the `annotate_type` attribute, which serves the same _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
