https://github.com/rnk created https://github.com/llvm/llvm-project/pull/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. >From 4cbb7fa32fd87e1add520a53d8ecc7443a00a29a Mon Sep 17 00:00:00 2001 From: Reid Kleckner <r...@google.com> Date: Thu, 22 Feb 2024 17:55:30 +0000 Subject: [PATCH] [clang] Note that optnone and target attributes do not apply to nested functions 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 funciton-wide attributes. There may be more, these were the two that came to mind. --- clang/include/clang/Basic/AttrDocs.td | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/clang/include/clang/Basic/AttrDocs.td b/clang/include/clang/Basic/AttrDocs.td index b96fbddd51154c..3c58256c77201f 100644 --- a/clang/include/clang/Basic/AttrDocs.td +++ b/clang/include/clang/Basic/AttrDocs.td @@ -2486,6 +2486,9 @@ Example "subtarget features" from the x86 backend include: "mmx", "sse", "sse4.2 "avx", "xop" and largely correspond to the machine specific options handled by the front end. +Note that this attribute does not apply transitively to nested functions such +as blocks or C++ lambdas. + Additionally, this attribute supports function multiversioning for ELF based x86/x86-64 targets, which can be used to create multiple implementations of the same function that will be resolved at runtime based on the priority of their @@ -3714,6 +3717,12 @@ for that function. This attribute is incompatible with the ``always_inline`` and ``minsize`` attributes. + +Note that this attribute does not apply recursively to nested functions such as +lambdas or blocks when using declaration-specific attribute syntaxes such as double +square brackets (``[[]]``) or ``__attribute__``. The ``#pragma`` syntax can be +used to apply the attribute to all functions, including nested functions, in a +range of source code. }]; } _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits