Teach SourceManager::getSLocEntry() that it can fail due to problems
during deserialization from a precompiled header, and update all of
its callers to note when this problem occurs and recover (more)
gracefully. Fixes <rdar://problem/9119249>.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@129839 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/tools/libclang/CIndex.cpp b/tools/libclang/CIndex.cpp
index dc74cd3..90d9881 100644
--- a/tools/libclang/CIndex.cpp
+++ b/tools/libclang/CIndex.cpp
@@ -2773,8 +2773,9 @@
// Check that the FileID is invalid on the instantiation location.
// This can manifest in invalid code.
FileID fileID = SM.getFileID(InstLoc);
- const SrcMgr::SLocEntry &sloc = SM.getSLocEntry(fileID);
- if (!sloc.isFile()) {
+ bool Invalid = false;
+ const SrcMgr::SLocEntry &sloc = SM.getSLocEntry(fileID, &Invalid);
+ if (!sloc.isFile() || Invalid) {
createNullLocation(file, line, column, offset);
return;
}
diff --git a/tools/libclang/CIndexInclusionStack.cpp b/tools/libclang/CIndexInclusionStack.cpp
index 9ea9019..6bc4f2e 100644
--- a/tools/libclang/CIndexInclusionStack.cpp
+++ b/tools/libclang/CIndexInclusionStack.cpp
@@ -40,10 +40,10 @@
i = 0;
for ( ; i < n ; ++i) {
-
- const SrcMgr::SLocEntry &SL = SM.getSLocEntry(i);
+ bool Invalid = false;
+ const SrcMgr::SLocEntry &SL = SM.getSLocEntry(i, &Invalid);
- if (!SL.isFile())
+ if (!SL.isFile() || Invalid)
continue;
const SrcMgr::FileInfo &FI = SL.getFile();