[libclang] When getting a source location from a file:line:col triplet
check whether the requested location points inside the precompiled preamble,
in which case the returned source location will be a "loaded" one.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@140060 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/tools/libclang/CIndex.cpp b/tools/libclang/CIndex.cpp
index 3654a58..8390a7c 100644
--- a/tools/libclang/CIndex.cpp
+++ b/tools/libclang/CIndex.cpp
@@ -2750,8 +2750,7 @@
bool Logging = ::getenv("LIBCLANG_LOGGING");
ASTUnit *CXXUnit = static_cast<ASTUnit *>(tu->TUData);
const FileEntry *File = static_cast<const FileEntry *>(file);
- SourceLocation SLoc
- = CXXUnit->getSourceManager().getLocation(File, line, column);
+ SourceLocation SLoc = CXXUnit->getLocation(File, line, column);
if (SLoc.isInvalid()) {
if (Logging)
llvm::errs() << "clang_getLocation(\"" << File->getName()
@@ -2774,14 +2773,8 @@
return clang_getNullLocation();
ASTUnit *CXXUnit = static_cast<ASTUnit *>(tu->TUData);
- SourceLocation Start
- = CXXUnit->getSourceManager().getLocation(
- static_cast<const FileEntry *>(file),
- 1, 1);
- if (Start.isInvalid()) return clang_getNullLocation();
-
- SourceLocation SLoc = Start.getLocWithOffset(offset);
-
+ SourceLocation SLoc
+ = CXXUnit->getLocation(static_cast<const FileEntry *>(file), offset);
if (SLoc.isInvalid()) return clang_getNullLocation();
return cxloc::translateSourceLocation(CXXUnit->getASTContext(), SLoc);