[clang] Thread Safety Analysis: Support attributes on function pointers (PR #191187)

Marco Elver via cfe-commits cfe-commits at lists.llvm.org
Wed Apr 29 06:51:02 PDT 2026


================
@@ -674,15 +674,28 @@ void Parser::ParseGNUAttributeArgs(
   // These may refer to the function arguments, but need to be parsed early to
   // participate in determining whether it's a redeclaration.
   std::optional<ParseScope> PrototypeScope;
-  if (normalizeAttrName(AttrName->getName()) == "enable_if" &&
-      D && D->isFunctionDeclarator()) {
-    const DeclaratorChunk::FunctionTypeInfo& FTI = D->getFunctionTypeInfo();
-    PrototypeScope.emplace(this, Scope::FunctionPrototypeScope |
-                                     Scope::FunctionDeclarationScope |
-                                     Scope::DeclScope);
-    for (unsigned i = 0; i != FTI.NumParams; ++i)
-      Actions.ActOnReenterCXXMethodParameter(
-          getCurScope(), dyn_cast_or_null<ParmVarDecl>(FTI.Params[i].Param));
+  if (D && (normalizeAttrName(AttrName->getName()) == "enable_if" ||
+            IsAttributeLateParsedStandard(*AttrName))) {
----------------
melver wrote:

I thought about this for a while - to not regress the existing behaviour, I don't think we can switch to `LateAttrParseExperimentalExt`. Furthermore, I acknowledge the check for `IsAttributeLateParsedStandard()` is probably misleading here - it's not strictly about late parsing, it just so happened that the TSA attributes are defined as `LateAttrParseStandard`.

What we actually want to say is "args may reference function parameters": I added a new orthogonal flag `ParseArgsInFunctionScope` (set on `EnableIf` and the six TSA call attrs, getting rid of the hacky hard-coded special casing).

https://github.com/llvm/llvm-project/pull/191187


More information about the cfe-commits mailing list