This revision was landed with ongoing or failed builds. This revision was automatically updated to reflect the committed changes. Closed by commit rG83546221af43: [include-cleaner] Ignore builtin symbols in the WalkAST. (authored by hokein).
Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D147213/new/ https://reviews.llvm.org/D147213 Files: clang-tools-extra/include-cleaner/lib/WalkAST.cpp clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp Index: clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp =================================================================== --- clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp +++ clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp @@ -322,5 +322,11 @@ testWalk("enum class E : int {};", "enum class ^E : int ;"); } +TEST(WalkAST, BuiltinSymbols) { + testWalk(R"cpp( + extern "C" int __builtin_popcount(unsigned int) noexcept; + )cpp", "int x = ^__builtin_popcount(1);"); +} + } // namespace } // namespace clang::include_cleaner Index: clang-tools-extra/include-cleaner/lib/WalkAST.cpp =================================================================== --- clang-tools-extra/include-cleaner/lib/WalkAST.cpp +++ clang-tools-extra/include-cleaner/lib/WalkAST.cpp @@ -17,6 +17,7 @@ #include "clang/AST/TemplateName.h" #include "clang/AST/Type.h" #include "clang/AST/TypeLoc.h" +#include "clang/Basic/IdentifierTable.h" #include "clang/Basic/SourceLocation.h" #include "llvm/ADT/STLExtras.h" #include "llvm/ADT/STLFunctionalExtras.h" @@ -34,6 +35,9 @@ RefType RT = RefType::Explicit) { if (!ND || Loc.isInvalid()) return; + // Don't report builtin symbols. + if (const auto *II = ND->getIdentifier(); II && II->getBuiltinID() > 0) + return; Callback(Loc, *cast<NamedDecl>(ND->getCanonicalDecl()), RT); }
Index: clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp =================================================================== --- clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp +++ clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp @@ -322,5 +322,11 @@ testWalk("enum class E : int {};", "enum class ^E : int ;"); } +TEST(WalkAST, BuiltinSymbols) { + testWalk(R"cpp( + extern "C" int __builtin_popcount(unsigned int) noexcept; + )cpp", "int x = ^__builtin_popcount(1);"); +} + } // namespace } // namespace clang::include_cleaner Index: clang-tools-extra/include-cleaner/lib/WalkAST.cpp =================================================================== --- clang-tools-extra/include-cleaner/lib/WalkAST.cpp +++ clang-tools-extra/include-cleaner/lib/WalkAST.cpp @@ -17,6 +17,7 @@ #include "clang/AST/TemplateName.h" #include "clang/AST/Type.h" #include "clang/AST/TypeLoc.h" +#include "clang/Basic/IdentifierTable.h" #include "clang/Basic/SourceLocation.h" #include "llvm/ADT/STLExtras.h" #include "llvm/ADT/STLFunctionalExtras.h" @@ -34,6 +35,9 @@ RefType RT = RefType::Explicit) { if (!ND || Loc.isInvalid()) return; + // Don't report builtin symbols. + if (const auto *II = ND->getIdentifier(); II && II->getBuiltinID() > 0) + return; Callback(Loc, *cast<NamedDecl>(ND->getCanonicalDecl()), RT); }
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits