[PATCH] D147213: [include-cleaner] Ignore builtin symbols in the WalkAST.
Haojian Wu via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Thu Mar 30 04:47:15 PDT 2023
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);
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D147213.509617.patch
Type: text/x-patch
Size: 1400 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230330/ee6acd92/attachment.bin>
More information about the cfe-commits
mailing list