[clang] [clang] Implement -Walloc-size diagnostic option (PR #150028)

Aaron Ballman via cfe-commits cfe-commits at lists.llvm.org
Wed Jul 30 09:58:23 PDT 2025


================
@@ -3542,6 +3542,59 @@ bool CallExpr::isBuiltinAssumeFalse(const ASTContext &Ctx) const {
          Arg->EvaluateAsBooleanCondition(ArgVal, Ctx) && !ArgVal;
 }
 
+const AllocSizeAttr *CallExpr::getAllocSizeAttr() const {
+  if (const FunctionDecl *DirectCallee = getDirectCallee())
+    return DirectCallee->getAttr<AllocSizeAttr>();
+  if (const Decl *IndirectCallee = getCalleeDecl())
+    return IndirectCallee->getAttr<AllocSizeAttr>();
+  return nullptr;
----------------
AaronBallman wrote:

I think that's something we could encode in the tablegen file for builtins; we already encode things like `const` attributes. Then when the (lib)builtin declaration is formed, we would already have the attribute present and this logic would just work.

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


More information about the cfe-commits mailing list