[clang] Add support for referencable labels for attribute documentation (PR #118428)
Oliver Hunt via cfe-commits
cfe-commits at lists.llvm.org
Wed Dec 4 00:14:18 PST 2024
https://github.com/ojhunt updated https://github.com/llvm/llvm-project/pull/118428
>From aea2b4001aa8e9239909875153152083b56a6a59 Mon Sep 17 00:00:00 2001
From: Oliver Hunt <oliver at apple.com>
Date: Mon, 2 Dec 2024 21:25:54 -0800
Subject: [PATCH 1/3] Add support for referencable labels for attribute
documentation
The existing mechanism being used is to manually add a reference in the
documentation. These references link to the beginning of the text rather
than the heading for the attribute which is what this PR allows.
---
clang/include/clang/Basic/Attr.td | 3 +++
clang/include/clang/Basic/AttrDocs.td | 12 ++++--------
clang/utils/TableGen/ClangAttrEmitter.cpp | 3 +++
3 files changed, 10 insertions(+), 8 deletions(-)
diff --git a/clang/include/clang/Basic/Attr.td b/clang/include/clang/Basic/Attr.td
index 618252f3e75247..522821a79063ac 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -55,6 +55,9 @@ class Documentation {
// When set, specifies that the attribute is deprecated and can optionally
// specify a replacement attribute.
DocDeprecated Deprecated;
+
+ // When set, specifies a label that can be used to reference the documentation
+ string Label = "";
}
// Specifies that the attribute is explicitly omitted from the documentation,
diff --git a/clang/include/clang/Basic/AttrDocs.td b/clang/include/clang/Basic/AttrDocs.td
index 5de39be4805600..7a82b8fa320590 100644
--- a/clang/include/clang/Basic/AttrDocs.td
+++ b/clang/include/clang/Basic/AttrDocs.td
@@ -3360,9 +3360,8 @@ def NoSanitizeAddressDocs : Documentation {
// This function has multiple distinct spellings, and so it requires a custom
// heading to be specified. The most common spelling is sufficient.
let Heading = "no_sanitize_address, no_address_safety_analysis";
+ let Label = "langext-address_sanitizer";
let Content = [{
-.. _langext-address_sanitizer:
-
Use ``__attribute__((no_sanitize_address))`` on a function or a global
variable declaration to specify that address safety instrumentation
(e.g. AddressSanitizer) should not be applied.
@@ -3372,9 +3371,8 @@ variable declaration to specify that address safety instrumentation
def NoSanitizeThreadDocs : Documentation {
let Category = DocCatFunction;
let Heading = "no_sanitize_thread";
+ let Label = "langext-thread_sanitizer";
let Content = [{
-.. _langext-thread_sanitizer:
-
Use ``__attribute__((no_sanitize_thread))`` on a function declaration to
specify that checks for data races on plain (non-atomic) memory accesses should
not be inserted by ThreadSanitizer. The function is still instrumented by the
@@ -3385,9 +3383,8 @@ tool to avoid false positives and provide meaningful stack traces.
def NoSanitizeMemoryDocs : Documentation {
let Category = DocCatFunction;
let Heading = "no_sanitize_memory";
+ let Label = "langext-memory_sanitizer";
let Content = [{
-.. _langext-memory_sanitizer:
-
Use ``__attribute__((no_sanitize_memory))`` on a function declaration to
specify that checks for uninitialized memory should not be inserted
(e.g. by MemorySanitizer). The function may still be instrumented by the tool
@@ -3398,9 +3395,8 @@ to avoid false positives in other places.
def CFICanonicalJumpTableDocs : Documentation {
let Category = DocCatFunction;
let Heading = "cfi_canonical_jump_table";
+ let Label = "langext-cfi_canonical_jump_table";
let Content = [{
-.. _langext-cfi_canonical_jump_table:
-
Use ``__attribute__((cfi_canonical_jump_table))`` on a function declaration to
make the function's CFI jump table canonical. See :ref:`the CFI documentation
<cfi-canonical-jump-tables>` for more details.
diff --git a/clang/utils/TableGen/ClangAttrEmitter.cpp b/clang/utils/TableGen/ClangAttrEmitter.cpp
index 534bf2d01d7957..60cb4ae452326d 100644
--- a/clang/utils/TableGen/ClangAttrEmitter.cpp
+++ b/clang/utils/TableGen/ClangAttrEmitter.cpp
@@ -5178,6 +5178,9 @@ GetAttributeHeadingAndSpellings(const Record &Documentation,
static void WriteDocumentation(const RecordKeeper &Records,
const DocumentationData &Doc, raw_ostream &OS) {
+ if (const StringRef label = Doc.Documentation->getValueAsString("Label");
+ !label.empty())
+ OS << ".. _" << label << ":\n\n";
OS << Doc.Heading << "\n" << std::string(Doc.Heading.length(), '-') << "\n";
// List what spelling syntaxes the attribute supports.
>From 3f05ad04019139789aff09dced2360bfa536afe8 Mon Sep 17 00:00:00 2001
From: Oliver Hunt <oliver at apple.com>
Date: Tue, 3 Dec 2024 21:24:22 -0800
Subject: [PATCH 2/3] Adjust style
---
clang/include/clang/Basic/Attr.td | 2 +-
clang/utils/TableGen/ClangAttrEmitter.cpp | 6 +++---
2 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/clang/include/clang/Basic/Attr.td b/clang/include/clang/Basic/Attr.td
index 522821a79063ac..17fc36fbe2ac8c 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -56,7 +56,7 @@ class Documentation {
// specify a replacement attribute.
DocDeprecated Deprecated;
- // When set, specifies a label that can be used to reference the documentation
+ // When set, specifies a label that can be used to reference the documentation.
string Label = "";
}
diff --git a/clang/utils/TableGen/ClangAttrEmitter.cpp b/clang/utils/TableGen/ClangAttrEmitter.cpp
index 60cb4ae452326d..25c1e4e4cbadb5 100644
--- a/clang/utils/TableGen/ClangAttrEmitter.cpp
+++ b/clang/utils/TableGen/ClangAttrEmitter.cpp
@@ -5178,9 +5178,9 @@ GetAttributeHeadingAndSpellings(const Record &Documentation,
static void WriteDocumentation(const RecordKeeper &Records,
const DocumentationData &Doc, raw_ostream &OS) {
- if (const StringRef label = Doc.Documentation->getValueAsString("Label");
- !label.empty())
- OS << ".. _" << label << ":\n\n";
+ if (const StringRef Label = Doc.Documentation->getValueAsString("Label");
+ !Label.empty())
+ OS << ".. _" << Label << ":\n\n";
OS << Doc.Heading << "\n" << std::string(Doc.Heading.length(), '-') << "\n";
// List what spelling syntaxes the attribute supports.
>From 8ed1f243da162954ddded45af873d02b3462a086 Mon Sep 17 00:00:00 2001
From: Oliver Hunt <github at nerget.com>
Date: Wed, 4 Dec 2024 00:14:10 -0800
Subject: [PATCH 3/3] Update clang/utils/TableGen/ClangAttrEmitter.cpp
Co-authored-by: Sirraide <aeternalmail at gmail.com>
---
clang/utils/TableGen/ClangAttrEmitter.cpp | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/clang/utils/TableGen/ClangAttrEmitter.cpp b/clang/utils/TableGen/ClangAttrEmitter.cpp
index 25c1e4e4cbadb5..630beaef983bc6 100644
--- a/clang/utils/TableGen/ClangAttrEmitter.cpp
+++ b/clang/utils/TableGen/ClangAttrEmitter.cpp
@@ -5178,7 +5178,7 @@ GetAttributeHeadingAndSpellings(const Record &Documentation,
static void WriteDocumentation(const RecordKeeper &Records,
const DocumentationData &Doc, raw_ostream &OS) {
- if (const StringRef Label = Doc.Documentation->getValueAsString("Label");
+ if (StringRef Label = Doc.Documentation->getValueAsString("Label");
!Label.empty())
OS << ".. _" << Label << ":\n\n";
OS << Doc.Heading << "\n" << std::string(Doc.Heading.length(), '-') << "\n";
More information about the cfe-commits
mailing list