Check for invalid after calling getSLocEntry, for safety.

llvm-svn: 143748
This commit is contained in:
Argyrios Kyrtzidis 2011-11-04 23:43:06 +00:00
parent 6b2d47d829
commit 088789caa6
1 changed files with 13 additions and 3 deletions

View File

@ -881,7 +881,11 @@ public:
/// offset from the start of the buffer of the location.
std::pair<FileID, unsigned> getDecomposedLoc(SourceLocation Loc) const {
FileID FID = getFileID(Loc);
return std::make_pair(FID, Loc.getOffset()-getSLocEntry(FID).getOffset());
bool Invalid = false;
const SrcMgr::SLocEntry &E = getSLocEntry(FID, &Invalid);
if (Invalid)
return std::make_pair(FileID(), 0);
return std::make_pair(FID, Loc.getOffset()-E.getOffset());
}
/// getDecomposedExpansionLoc - Decompose the specified location into a raw
@ -890,7 +894,10 @@ public:
std::pair<FileID, unsigned>
getDecomposedExpansionLoc(SourceLocation Loc) const {
FileID FID = getFileID(Loc);
const SrcMgr::SLocEntry *E = &getSLocEntry(FID);
bool Invalid = false;
const SrcMgr::SLocEntry *E = &getSLocEntry(FID, &Invalid);
if (Invalid)
return std::make_pair(FileID(), 0);
unsigned Offset = Loc.getOffset()-E->getOffset();
if (Loc.isFileID())
@ -905,7 +912,10 @@ public:
std::pair<FileID, unsigned>
getDecomposedSpellingLoc(SourceLocation Loc) const {
FileID FID = getFileID(Loc);
const SrcMgr::SLocEntry *E = &getSLocEntry(FID);
bool Invalid = false;
const SrcMgr::SLocEntry *E = &getSLocEntry(FID, &Invalid);
if (Invalid)
return std::make_pair(FileID(), 0);
unsigned Offset = Loc.getOffset()-E->getOffset();
if (Loc.isFileID())