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>"); }
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>"); }
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits