Skip to content

Commit cdbc297

Browse files
authored
include-cleaner: Report function decls from __cleanup__ as used (#138669)
1 parent d2dafde commit cdbc297

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

clang-tools-extra/include-cleaner/lib/WalkAST.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,11 @@ class ASTWalker : public RecursiveASTVisitor<ASTWalker> {
321321
return true;
322322
}
323323

324+
bool VisitCleanupAttr(CleanupAttr *attr) {
325+
report(attr->getLocation(), attr->getFunctionDecl());
326+
return true;
327+
}
328+
324329
// TypeLoc visitors.
325330
void reportType(SourceLocation RefLoc, NamedDecl *ND) {
326331
// Reporting explicit references to types nested inside classes can cause

clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -570,5 +570,11 @@ TEST(WalkAST, OperatorNewDelete) {
570570
testWalk("struct A { static void $ambiguous^operator delete(void*); };",
571571
"void foo() { A a; ^delete &a; }");
572572
}
573+
574+
TEST(WalkAST, CleanupAttr) {
575+
testWalk("void* $explicit^freep(void *p);",
576+
"void foo() { __attribute__((^__cleanup__(freep))) char* x = 0; }");
577+
}
578+
573579
} // namespace
574580
} // namespace clang::include_cleaner

0 commit comments

Comments
 (0)