Author: Daan De Meyer
Date: 2025-05-13T10:22:32+02:00
New Revision: cdbc297ef53fcc784dc0b5661daaba17ea003f3c

URL: 
https://github.com/llvm/llvm-project/commit/cdbc297ef53fcc784dc0b5661daaba17ea003f3c
DIFF: 
https://github.com/llvm/llvm-project/commit/cdbc297ef53fcc784dc0b5661daaba17ea003f3c.diff

LOG: include-cleaner: Report function decls from __cleanup__ as used (#138669)

Added: 
    

Modified: 
    clang-tools-extra/include-cleaner/lib/WalkAST.cpp
    clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp

Removed: 
    


################################################################################
diff  --git a/clang-tools-extra/include-cleaner/lib/WalkAST.cpp 
b/clang-tools-extra/include-cleaner/lib/WalkAST.cpp
index dff0c711f04c5..ba6eff49e9c98 100644
--- a/clang-tools-extra/include-cleaner/lib/WalkAST.cpp
+++ b/clang-tools-extra/include-cleaner/lib/WalkAST.cpp
@@ -321,6 +321,11 @@ class ASTWalker : public RecursiveASTVisitor<ASTWalker> {
     return true;
   }
 
+  bool VisitCleanupAttr(CleanupAttr *attr) {
+    report(attr->getLocation(), attr->getFunctionDecl());
+    return true;
+  }
+
   // TypeLoc visitors.
   void reportType(SourceLocation RefLoc, NamedDecl *ND) {
     // Reporting explicit references to types nested inside classes can cause

diff  --git a/clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp 
b/clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp
index e45ea36f7938e..19695a34bd63e 100644
--- a/clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp
+++ b/clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp
@@ -570,5 +570,11 @@ TEST(WalkAST, OperatorNewDelete) {
   testWalk("struct A { static void $ambiguous^operator delete(void*); };",
            "void foo() { A a; ^delete &a; }");
 }
+
+TEST(WalkAST, CleanupAttr) {
+  testWalk("void* $explicit^freep(void *p);",
+           "void foo() { __attribute__((^__cleanup__(freep))) char* x = 0; }");
+}
+
 } // namespace
 } // namespace clang::include_cleaner


        
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to