Make clang_isFromMainFile() robust against NULL source locations.

llvm-svn: 104474
This commit is contained in:
Douglas Gregor 2010-05-23 21:31:22 +00:00
parent dc99965343
commit 01308a0e11
1 changed files with 3 additions and 0 deletions

View File

@ -1481,6 +1481,9 @@ CXSourceLocation clang_getRangeEnd(CXSourceRange range) {
unsigned clang_isFromMainFile(CXSourceLocation loc) {
SourceLocation Loc = SourceLocation::getFromRawEncoding(loc.int_data);
if (!loc.ptr_data[0] || Loc.isInvalid())
return 0;
const SourceManager &SM =
*static_cast<const SourceManager*>(loc.ptr_data[0]);
return SM.isFromMainFile(Loc) ? 1 : 0;