llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT--> @llvm/pr-subscribers-clang @llvm/pr-subscribers-clang-tools-extra Author: Daan De Meyer (DaanDeMeyer) <details> <summary>Changes</summary> Instead of reporting the location of the attribute, let's report the location of the function reference that's passed to the cleanup attribute as the first argument. This is required as the attribute might be coming from a macro which means clang-include-cleaner skips the use as it gets attributed to the header file declaringt the macro and not to the main file. To make this work, we have to add a fake argument to the CleanupAttr constructor so we can pass in the original Expr alongside the function declaration. Fixes #<!-- -->140212 --- Full diff: https://github.com/llvm/llvm-project/pull/140233.diff 4 Files Affected: - (modified) clang-tools-extra/include-cleaner/lib/WalkAST.cpp (+1-1) - (modified) clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp (+1-1) - (modified) clang/include/clang/Basic/Attr.td (+4-2) - (modified) clang/lib/Sema/SemaDeclAttr.cpp (+1-1) ``````````diff diff --git a/clang-tools-extra/include-cleaner/lib/WalkAST.cpp b/clang-tools-extra/include-cleaner/lib/WalkAST.cpp index ba6eff49e9c98..a6f2559dd8e93 100644 --- a/clang-tools-extra/include-cleaner/lib/WalkAST.cpp +++ b/clang-tools-extra/include-cleaner/lib/WalkAST.cpp @@ -322,7 +322,7 @@ class ASTWalker : public RecursiveASTVisitor<ASTWalker> { } bool VisitCleanupAttr(CleanupAttr *attr) { - report(attr->getLocation(), attr->getFunctionDecl()); + report(attr->getExpr()->getExprLoc(), attr->getFunctionDecl()); return true; } diff --git a/clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp b/clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp index 19695a34bd63e..0de0b77f33daf 100644 --- a/clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp +++ b/clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp @@ -573,7 +573,7 @@ TEST(WalkAST, OperatorNewDelete) { TEST(WalkAST, CleanupAttr) { testWalk("void* $explicit^freep(void *p);", - "void foo() { __attribute__((^__cleanup__(freep))) char* x = 0; }"); + "void foo() { __attribute__((__cleanup__(^freep))) char* x = 0; }"); } } // namespace diff --git a/clang/include/clang/Basic/Attr.td b/clang/include/clang/Basic/Attr.td index ccd13a4cca4dd..e90d18d8435bf 100644 --- a/clang/include/clang/Basic/Attr.td +++ b/clang/include/clang/Basic/Attr.td @@ -226,7 +226,8 @@ class BoolArgument<string name, bit opt = 0, bit fake = 0> : Argument<name, opt, class IdentifierArgument<string name, bit opt = 0> : Argument<name, opt>; class IntArgument<string name, bit opt = 0> : Argument<name, opt>; class StringArgument<string name, bit opt = 0> : Argument<name, opt>; -class ExprArgument<string name, bit opt = 0> : Argument<name, opt>; +class ExprArgument<string name, bit opt = 0, bit fake = 0> : Argument<name, opt, + fake>; class DeclArgument<DeclNode kind, string name, bit opt = 0, bit fake = 0> : Argument<name, opt, fake> { DeclNode Kind = kind; @@ -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", /*fake=*/1>]; let Subjects = SubjectList<[LocalVar]>; let Documentation = [CleanupDocs]; } diff --git a/clang/lib/Sema/SemaDeclAttr.cpp b/clang/lib/Sema/SemaDeclAttr.cpp index 377595639bef1..6b1a42bcc392f 100644 --- a/clang/lib/Sema/SemaDeclAttr.cpp +++ b/clang/lib/Sema/SemaDeclAttr.cpp @@ -3620,7 +3620,7 @@ static void handleCleanupAttr(Sema &S, Decl *D, const ParsedAttr &AL) { return; } - D->addAttr(::new (S.Context) CleanupAttr(S.Context, AL, FD)); + D->addAttr(::new (S.Context) CleanupAttr(S.Context, AL, FD, E)); } static void handleEnumExtensibilityAttr(Sema &S, Decl *D, `````````` </details> https://github.com/llvm/llvm-project/pull/140233 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits