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

This commit is contained in:
Daan De Meyer
2025-05-13 10:22:32 +02:00
committed by GitHub
parent d2dafded03
commit cdbc297ef5
2 changed files with 11 additions and 0 deletions

View File

@@ -321,6 +321,11 @@ public:
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

View File

@@ -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