]> granicus.if.org Git - clang/commitdiff
[modules] If loading a .pcm file would cause us to run out of source locations, attem...
authorRichard Smith <richard-llvm@metafoo.co.uk>
Wed, 12 Aug 2015 22:25:24 +0000 (22:25 +0000)
committerRichard Smith <richard-llvm@metafoo.co.uk>
Wed, 12 Aug 2015 22:25:24 +0000 (22:25 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@244822 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Basic/SourceManager.cpp
lib/Serialization/ASTReader.cpp

index c0b045331dd641fdde3c73bdf15db3d556bdbe3b..6c2bd7d2332f268e666dff231d0931163959fc62 100644 (file)
@@ -484,10 +484,12 @@ std::pair<int, unsigned>
 SourceManager::AllocateLoadedSLocEntries(unsigned NumSLocEntries,
                                          unsigned TotalSize) {
   assert(ExternalSLocEntries && "Don't have an external sloc source");
+  // Make sure we're not about to run out of source locations.
+  if (CurrentLoadedOffset - TotalSize < NextLocalOffset)
+    return std::make_pair(0, 0);
   LoadedSLocEntryTable.resize(LoadedSLocEntryTable.size() + NumSLocEntries);
   SLocEntryLoaded.resize(LoadedSLocEntryTable.size());
   CurrentLoadedOffset -= TotalSize;
-  assert(CurrentLoadedOffset >= NextLocalOffset && "Out of source locations");
   int ID = LoadedSLocEntryTable.size();
   return std::make_pair(-ID - 1, CurrentLoadedOffset);
 }
index 91dc4bdbc90e390a1bff79089746bd2b617e4079..e950bdf40fa8058e5521f349e495af8fb84c1183 100644 (file)
@@ -2727,6 +2727,10 @@ ASTReader::ReadASTBlock(ModuleFile &F, unsigned ClientLoadCapabilities) {
       std::tie(F.SLocEntryBaseID, F.SLocEntryBaseOffset) =
           SourceMgr.AllocateLoadedSLocEntries(F.LocalNumSLocEntries,
                                               SLocSpaceSize);
+      if (!F.SLocEntryBaseID) {
+        Error("ran out of source locations");
+        break;
+      }
       // Make our entry in the range map. BaseID is negative and growing, so
       // we invert it. Because we invert it, though, we need the other end of
       // the range.