[clang] [clang][Sema] Handle alloc_align on all HasFunctionProto declarations (PR #210871)
Aaron Ballman via cfe-commits
cfe-commits at lists.llvm.org
Tue Jul 21 07:48:07 PDT 2026
================
@@ -1509,16 +1509,15 @@ void Sema::AddAllocAlignAttr(Decl *D, const AttributeCommonInfo &CI,
}
ParamIdx Idx;
- const auto *FuncDecl = cast<FunctionDecl>(D);
- if (!checkFunctionOrMethodParameterIndex(FuncDecl, CI,
+ if (!checkFunctionOrMethodParameterIndex(D, CI,
/*AttrArgNum=*/1, ParamExpr, Idx))
return;
QualType Ty = getFunctionOrMethodParamType(D, Idx.getASTIndex());
if (!Ty->isDependentType() && !Ty->isIntegralType(Context) &&
!Ty->isAlignValT()) {
Diag(ParamExpr->getBeginLoc(), diag::err_attribute_integers_only)
- << CI << FuncDecl->getParamDecl(Idx.getASTIndex())->getSourceRange();
+ << CI << getFunctionOrMethodParamRange(D, Idx.getASTIndex());
----------------
AaronBallman wrote:
I'm not seeing the issue you're concerned by. `D` is either a `FunctionDecl` to a function with a prototype, a `BlockDecl`, or an `ObjCMethodDecl` (per the `Subjects` list for the attribute in `Attr.td`). `getFunctionOrMethodParamRange()` handles exactly those cases, so this should result in a non-empty `SourceRange` in the cases we expect to handle, and we shouldn't get here for other declaration kinds.
https://github.com/llvm/llvm-project/pull/210871
More information about the cfe-commits
mailing list