[clang] Thread Safety Analysis: Support attributes on function pointers (PR #191187)
Aaron Puchert via cfe-commits
cfe-commits at lists.llvm.org
Sun Apr 19 15:39:59 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))) {
+ // 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;
----------------
aaronpuchert wrote:
This also looks to me like we actually want a type attribute.
https://github.com/llvm/llvm-project/pull/191187
More information about the cfe-commits
mailing list