[PATCH] D88780: Allow interfaces to operate on in-memory buffers with no source location info.

Pratyush Das via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Sat Oct 3 03:05:37 PDT 2020


reikdas created this revision.
reikdas added reviewers: rsmith, lebedev.ri, shafik, v.g.vassilev.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.
reikdas requested review of this revision.

This is a part of the RFC mentioned here - https://lists.llvm.org/pipermail/cfe-dev/2020-July/066203.html where we plan to move parts of Cling upstream.

Cling has the ability to spawn child interpreters (mainly for auto completions). We needed
to apply this patch on top of our fork of Clang, because otherwise when we try to
import a Decl into the Cling child interpreter using
Clang::ASTImporter, the assertion here - https://github.com/llvm/llvm-project/blob/65eb74e94b414fcde6bfa810d1c30c7fcb136b77/clang/include/clang/Basic/SourceLocation.h#L322 fails.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D88780

Files:
  clang/include/clang/Basic/SourceManager.h


Index: clang/include/clang/Basic/SourceManager.h
===================================================================
--- clang/include/clang/Basic/SourceManager.h
+++ clang/include/clang/Basic/SourceManager.h
@@ -1440,19 +1440,28 @@
 
   /// Returns whether \p Loc is located in a <built-in> file.
   bool isWrittenInBuiltinFile(SourceLocation Loc) const {
-    StringRef Filename(getPresumedLoc(Loc).getFilename());
+    PresumedLoc Presumed = getPresumedLoc(Loc);
+    if (Presumed.isInvalid())
+      return false;
+    StringRef Filename(Presumed.getFilename());
     return Filename.equals("<built-in>");
   }
 
   /// Returns whether \p Loc is located in a <command line> file.
   bool isWrittenInCommandLineFile(SourceLocation Loc) const {
-    StringRef Filename(getPresumedLoc(Loc).getFilename());
+    PresumedLoc Presumed = getPresumedLoc(Loc);
+    if (Presumed.isInvalid())
+      return false;
+    StringRef Filename(Presumed.getFilename());
     return Filename.equals("<command line>");
   }
 
   /// Returns whether \p Loc is located in a <scratch space> file.
   bool isWrittenInScratchSpace(SourceLocation Loc) const {
-    StringRef Filename(getPresumedLoc(Loc).getFilename());
+    PresumedLoc Presumed = getPresumedLoc(Loc);
+    if (Presumed.isInvalid())
+      return false;
+    StringRef Filename(Presumed.getFilename());
     return Filename.equals("<scratch space>");
   }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D88780.295971.patch
Type: text/x-patch
Size: 1404 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20201003/001e56b8/attachment.bin>


More information about the cfe-commits mailing list