diff --git a/clang/include/clang/Basic/Attr.td b/clang/include/clang/Basic/Attr.td index 618252f3e7524..17fc36fbe2ac8 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 5de39be480560..7a82b8fa32059 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 ` for more details. diff --git a/clang/utils/TableGen/ClangAttrEmitter.cpp b/clang/utils/TableGen/ClangAttrEmitter.cpp index 534bf2d01d795..630beaef983bc 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 (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.