[clang] [clang-tools-extra] [clang-include-cleaner] Make cleanup attr report expr location (PR #140233)

Aaron Ballman via cfe-commits cfe-commits at lists.llvm.org
Mon May 19 12:10:40 PDT 2025


================
@@ -1351,7 +1352,8 @@ def OSConsumesThis : InheritableAttr {
 
 def Cleanup : InheritableAttr {
   let Spellings = [GCC<"cleanup">];
-  let Args = [DeclArgument<Function, "FunctionDecl">];
+  let Args = [DeclArgument<Function, "FunctionDecl">,
+              ExprArgument<"Expr", /*opt=*/0, /*fake=*/1>];
----------------
AaronBallman wrote:

It's safe to ignore us for the moment because we're just discussing what way to go forward so we can give you actual advice. :-D

(1) Basically boils down to changing `clang/utils/TableGen/ClangAttrEmitter.cpp` so that `DeclArgument` generates code differently. Currently it requires the attribute subclasses to pass in a declaration pointer, and now we'd want it to either take a declaration pointer and an expression pointer, or take a `const DeclRefExpr *` and automatically find the declaration from it as-needed.

(2) Basically boils down to adding `AdditionalMembers` for a source location, so it's pretty hacky but very direct.

I think our preference is for (1) because that's a general solution that will help all attributes. I think we can probably live with (2) though.

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


More information about the cfe-commits mailing list