[PATCH] D145364: [include-cleaner] Fix a crash on non-identifier-name symbols.

Haojian Wu via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Mar 6 04:25:29 PST 2023


This revision was automatically updated to reflect the committed changes.
Closed by commit rGb2897ad70301: [include-cleaner] Fix a crash on non-identifier-name symbols. (authored by hokein).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D145364/new/

https://reviews.llvm.org/D145364

Files:
  clang-tools-extra/include-cleaner/lib/FindHeaders.cpp
  clang-tools-extra/include-cleaner/test/nocrash.cpp


Index: clang-tools-extra/include-cleaner/test/nocrash.cpp
===================================================================
--- /dev/null
+++ 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);
Index: clang-tools-extra/include-cleaner/lib/FindHeaders.cpp
===================================================================
--- clang-tools-extra/include-cleaner/lib/FindHeaders.cpp
+++ clang-tools-extra/include-cleaner/lib/FindHeaders.cpp
@@ -118,7 +118,7 @@
   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)


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D145364.502586.patch
Type: text/x-patch
Size: 936 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230306/b61ae436/attachment-0001.bin>


More information about the cfe-commits mailing list