Skip to content

Commit fe4bba6

Browse files
ojhuntSirraide
andauthored
Add support for referencable labels for attribute documentation (#118428)
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. --------- Co-authored-by: Sirraide <[email protected]>
1 parent 842d563 commit fe4bba6

File tree

3 files changed

+10
-8
lines changed

3 files changed

+10
-8
lines changed

clang/include/clang/Basic/Attr.td

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,9 @@ class Documentation {
5555
// When set, specifies that the attribute is deprecated and can optionally
5656
// specify a replacement attribute.
5757
DocDeprecated Deprecated;
58+
59+
// When set, specifies a label that can be used to reference the documentation.
60+
string Label = "";
5861
}
5962

6063
// Specifies that the attribute is explicitly omitted from the documentation,

clang/include/clang/Basic/AttrDocs.td

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3360,9 +3360,8 @@ def NoSanitizeAddressDocs : Documentation {
33603360
// This function has multiple distinct spellings, and so it requires a custom
33613361
// heading to be specified. The most common spelling is sufficient.
33623362
let Heading = "no_sanitize_address, no_address_safety_analysis";
3363+
let Label = "langext-address_sanitizer";
33633364
let Content = [{
3364-
.. _langext-address_sanitizer:
3365-
33663365
Use ``__attribute__((no_sanitize_address))`` on a function or a global
33673366
variable declaration to specify that address safety instrumentation
33683367
(e.g. AddressSanitizer) should not be applied.
@@ -3372,9 +3371,8 @@ variable declaration to specify that address safety instrumentation
33723371
def NoSanitizeThreadDocs : Documentation {
33733372
let Category = DocCatFunction;
33743373
let Heading = "no_sanitize_thread";
3374+
let Label = "langext-thread_sanitizer";
33753375
let Content = [{
3376-
.. _langext-thread_sanitizer:
3377-
33783376
Use ``__attribute__((no_sanitize_thread))`` on a function declaration to
33793377
specify that checks for data races on plain (non-atomic) memory accesses should
33803378
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.
33853383
def NoSanitizeMemoryDocs : Documentation {
33863384
let Category = DocCatFunction;
33873385
let Heading = "no_sanitize_memory";
3386+
let Label = "langext-memory_sanitizer";
33883387
let Content = [{
3389-
.. _langext-memory_sanitizer:
3390-
33913388
Use ``__attribute__((no_sanitize_memory))`` on a function declaration to
33923389
specify that checks for uninitialized memory should not be inserted
33933390
(e.g. by MemorySanitizer). The function may still be instrumented by the tool
@@ -3398,9 +3395,8 @@ to avoid false positives in other places.
33983395
def CFICanonicalJumpTableDocs : Documentation {
33993396
let Category = DocCatFunction;
34003397
let Heading = "cfi_canonical_jump_table";
3398+
let Label = "langext-cfi_canonical_jump_table";
34013399
let Content = [{
3402-
.. _langext-cfi_canonical_jump_table:
3403-
34043400
Use ``__attribute__((cfi_canonical_jump_table))`` on a function declaration to
34053401
make the function's CFI jump table canonical. See :ref:`the CFI documentation
34063402
<cfi-canonical-jump-tables>` for more details.

clang/utils/TableGen/ClangAttrEmitter.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5178,6 +5178,9 @@ GetAttributeHeadingAndSpellings(const Record &Documentation,
51785178

51795179
static void WriteDocumentation(const RecordKeeper &Records,
51805180
const DocumentationData &Doc, raw_ostream &OS) {
5181+
if (StringRef Label = Doc.Documentation->getValueAsString("Label");
5182+
!Label.empty())
5183+
OS << ".. _" << Label << ":\n\n";
51815184
OS << Doc.Heading << "\n" << std::string(Doc.Heading.length(), '-') << "\n";
51825185

51835186
// List what spelling syntaxes the attribute supports.

0 commit comments

Comments
 (0)