[clang-tools-extra] 0a50eaf - [clangd] Stop isSpelledInSource from printing source locations.

Sam McCall via cfe-commits cfe-commits at lists.llvm.org
Wed Oct 5 07:27:13 PDT 2022


Author: Sam McCall
Date: 2022-10-05T15:49:22+02:00
New Revision: 0a50eafd1d44fae786a673e44831dd130a21b057

URL: https://github.com/llvm/llvm-project/commit/0a50eafd1d44fae786a673e44831dd130a21b057
DIFF: https://github.com/llvm/llvm-project/commit/0a50eafd1d44fae786a673e44831dd130a21b057.diff

LOG: [clangd] Stop isSpelledInSource from printing source locations.

It shows up on profiles, albeit only at 0.1% or so.

Added: 
    

Modified: 
    clang-tools-extra/clangd/SourceCode.cpp

Removed: 
    


################################################################################
diff  --git a/clang-tools-extra/clangd/SourceCode.cpp b/clang-tools-extra/clangd/SourceCode.cpp
index 670289eb37a5e..5928541635e67 100644
--- a/clang-tools-extra/clangd/SourceCode.cpp
+++ b/clang-tools-extra/clangd/SourceCode.cpp
@@ -228,12 +228,16 @@ Position sourceLocToPosition(const SourceManager &SM, SourceLocation Loc) {
 }
 
 bool isSpelledInSource(SourceLocation Loc, const SourceManager &SM) {
-  if (Loc.isMacroID()) {
-    std::string PrintLoc = SM.getSpellingLoc(Loc).printToString(SM);
-    if (llvm::StringRef(PrintLoc).startswith("<scratch") ||
-        llvm::StringRef(PrintLoc).startswith("<command line>"))
-      return false;
-  }
+  if (Loc.isFileID())
+    return true;
+  auto Spelling = SM.getDecomposedSpellingLoc(Loc);
+  StringRef SpellingFile = SM.getSLocEntry(Spelling.first).getFile().getName();
+  if (SpellingFile == "<scratch space>")
+    return false;
+  if (SpellingFile == "<built-in>")
+    // __STDC__ etc are considered spelled, but BAR in arg -DFOO=BAR is not.
+    return !SM.isWrittenInCommandLineFile(
+        SM.getComposedLoc(Spelling.first, Spelling.second));
   return true;
 }
 


        


More information about the cfe-commits mailing list