[clang] Thread Safety Analysis: Support attributes on function pointers (PR #191187)
Marco Elver via cfe-commits
cfe-commits at lists.llvm.org
Thu Apr 30 08:36:48 PDT 2026
================
@@ -674,15 +684,27 @@ 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 && IsAttributeArgsParsedInFunctionScope(*AttrName)) {
+ // Find the innermost function chunk to make its parameters available for
+ // attribute argument parsing. This is necessary for attributes like thread
+ // safety annotations on function pointers which reference their parameters.
+ for (unsigned i = 0; i < D->getNumTypeObjects(); ++i) {
+ if (D->getTypeObject(i).Kind == DeclaratorChunk::Function) {
+ const DeclaratorChunk::FunctionTypeInfo &FTI = D->getTypeObject(i).Fun;
+ // Inherit the class scope flag from the current context. This is safe
+ // because it only preserves existing struct/class visibility, which is
+ // required for attributes to resolve sibling members in C structs.
+ PrototypeScope.emplace(
----------------
melver wrote:
Moved out.
https://github.com/llvm/llvm-project/pull/191187
More information about the cfe-commits
mailing list