Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 13, 2025

Conversation

DaanDeMeyer
Copy link
Contributor

No description provided.

@llvmbot
Copy link
Member

llvmbot commented May 6, 2025

@llvm/pr-subscribers-clang-tools-extra

Author: Daan De Meyer (DaanDeMeyer)

Changes

Full diff: https://github.com/llvm/llvm-project/pull/138669.diff

2 Files Affected:

  • (modified) clang-tools-extra/include-cleaner/lib/WalkAST.cpp (+5)
  • (modified) clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp (+6)
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

@DaanDeMeyer
Copy link
Contributor Author

Ping @llvm/pr-subscribers-clangd @kadircet

Copy link
Member

@kadircet kadircet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks, sorry for missing this!

@DaanDeMeyer
Copy link
Contributor Author

@kadircet Can you merge this for me? I got rid of my contributor access as I don't contribute enough to justify having it.

@kadircet kadircet merged commit cdbc297 into llvm:main May 13, 2025
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants