[clang-tools-extra] b2897ad - [include-cleaner] Fix a crash on non-identifier-name symbols.
Haojian Wu via cfe-commits
cfe-commits at lists.llvm.org
Mon Mar 6 04:25:15 PST 2023
Author: Haojian Wu
Date: 2023-03-06T13:18:43+01:00
New Revision: b2897ad70301ae669328795eebc894d383d787c1
URL: https://github.com/llvm/llvm-project/commit/b2897ad70301ae669328795eebc894d383d787c1
DIFF: https://github.com/llvm/llvm-project/commit/b2897ad70301ae669328795eebc894d383d787c1.diff
LOG: [include-cleaner] Fix a crash on non-identifier-name symbols.
Differential Revision: https://reviews.llvm.org/D145364
Added:
clang-tools-extra/include-cleaner/test/nocrash.cpp
Modified:
clang-tools-extra/include-cleaner/lib/FindHeaders.cpp
Removed:
################################################################################
diff --git a/clang-tools-extra/include-cleaner/lib/FindHeaders.cpp b/clang-tools-extra/include-cleaner/lib/FindHeaders.cpp
index ae2a3a858a38c..e273d429cd8c3 100644
--- a/clang-tools-extra/include-cleaner/lib/FindHeaders.cpp
+++ b/clang-tools-extra/include-cleaner/lib/FindHeaders.cpp
@@ -118,7 +118,7 @@ headersForSpecialSymbol(const Symbol &S, const SourceManager &SM,
if (!FD)
return {};
- llvm::StringRef FName = FD->getName();
+ llvm::StringRef FName = symbolName(S);
llvm::SmallVector<tooling::stdlib::Header> Headers;
if (FName == "move") {
if (FD->getNumParams() == 1)
diff --git a/clang-tools-extra/include-cleaner/test/nocrash.cpp b/clang-tools-extra/include-cleaner/test/nocrash.cpp
new file mode 100644
index 0000000000000..60e0f098867c6
--- /dev/null
+++ b/clang-tools-extra/include-cleaner/test/nocrash.cpp
@@ -0,0 +1,8 @@
+// RUN: clang-include-cleaner %s --
+
+namespace std {
+class Foo {};
+bool operator==(Foo, int) { return false; }
+}
+// no crash on a reference to a non-identifier symbol (operator ==).
+bool s = std::operator==(std::Foo(), 1);
More information about the cfe-commits
mailing list