Skip to content

Commit 4e6d30e

Browse files
authored
[clang] Note that optnone and target attributes do not apply to nested functions (#82815)
This behavior is true for all attributes, but this behavior can be surprising for attributes which have function-wide effects, such as `optnone` and `target`. Most other function attributes affect the prototype or semantics, but do not affect code generation in the function body. I believe it is worth calling this out in the documentation of these function-wide attributes. There may be more, these were the two that came to mind.
1 parent b8d38bb commit 4e6d30e

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

clang/include/clang/Basic/AttrDocs.td

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2527,6 +2527,9 @@ Example "subtarget features" from the x86 backend include: "mmx", "sse", "sse4.2
25272527
"avx", "xop" and largely correspond to the machine specific options handled by
25282528
the front end.
25292529

2530+
Note that this attribute does not apply transitively to nested functions such
2531+
as blocks or C++ lambdas.
2532+
25302533
Additionally, this attribute supports function multiversioning for ELF based
25312534
x86/x86-64 targets, which can be used to create multiple implementations of the
25322535
same function that will be resolved at runtime based on the priority of their
@@ -3782,6 +3785,12 @@ for that function.
37823785

37833786
This attribute is incompatible with the ``always_inline`` and ``minsize``
37843787
attributes.
3788+
3789+
Note that this attribute does not apply recursively to nested functions such as
3790+
lambdas or blocks when using declaration-specific attribute syntaxes such as double
3791+
square brackets (``[[]]``) or ``__attribute__``. The ``#pragma`` syntax can be
3792+
used to apply the attribute to all functions, including nested functions, in a
3793+
range of source code.
37853794
}];
37863795
}
37873796

0 commit comments

Comments
 (0)