diff options
| author | Argyrios Kyrtzidis <akyrtzi@gmail.com> | 2013-05-24 22:24:04 +0000 |
|---|---|---|
| committer | Argyrios Kyrtzidis <akyrtzi@gmail.com> | 2013-05-24 22:24:04 +0000 |
| commit | 5b8e132a9ab2232fae55ee481bf4901b0a7005da (patch) | |
| tree | f2d4b1de092ab37e3410af2426bacfa426d180ea /lib/Basic/SourceManager.cpp | |
| parent | b9814c867e69d542ea6b90c756814dab462019c7 (diff) | |
| download | clang-5b8e132a9ab2232fae55ee481bf4901b0a7005da.tar.gz clang-5b8e132a9ab2232fae55ee481bf4901b0a7005da.tar.bz2 clang-5b8e132a9ab2232fae55ee481bf4901b0a7005da.tar.xz | |
Add some safety checks in a couple of SourceManager functions.
This is to address crash in rdar://13932308
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@182681 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Basic/SourceManager.cpp')
| -rw-r--r-- | lib/Basic/SourceManager.cpp | 19 |
1 files changed, 14 insertions, 5 deletions
diff --git a/lib/Basic/SourceManager.cpp b/lib/Basic/SourceManager.cpp index 9cfa5b9f45..a4f4f9d366 100644 --- a/lib/Basic/SourceManager.cpp +++ b/lib/Basic/SourceManager.cpp @@ -1958,6 +1958,9 @@ SourceManager::getMacroArgExpandedLocation(SourceLocation Loc) const { std::pair<FileID, unsigned> SourceManager::getDecomposedIncludedLoc(FileID FID) const { + if (FID.isInvalid()) + return std::make_pair(FileID(), 0); + // Uses IncludedLocMap to retrieve/cache the decomposed loc. typedef std::pair<FileID, unsigned> DecompTy; @@ -1969,11 +1972,14 @@ SourceManager::getDecomposedIncludedLoc(FileID FID) const { return DecompLoc; // already in map. SourceLocation UpperLoc; - const SrcMgr::SLocEntry &Entry = getSLocEntry(FID); - if (Entry.isExpansion()) - UpperLoc = Entry.getExpansion().getExpansionLocStart(); - else - UpperLoc = Entry.getFile().getIncludeLoc(); + bool Invalid = false; + const SrcMgr::SLocEntry &Entry = getSLocEntry(FID, &Invalid); + if (!Invalid) { + if (Entry.isExpansion()) + UpperLoc = Entry.getExpansion().getExpansionLocStart(); + else + UpperLoc = Entry.getFile().getIncludeLoc(); + } if (UpperLoc.isValid()) DecompLoc = getDecomposedLoc(UpperLoc); @@ -2033,6 +2039,9 @@ bool SourceManager::isBeforeInTranslationUnit(SourceLocation LHS, std::pair<FileID, unsigned> LOffs = getDecomposedLoc(LHS); std::pair<FileID, unsigned> ROffs = getDecomposedLoc(RHS); + if (LOffs.first.isInvalid() || ROffs.first.isInvalid()) + return false; + // If the source locations are in the same file, just compare offsets. if (LOffs.first == ROffs.first) return LOffs.second < ROffs.second; |
