]> granicus.if.org Git - clang/commitdiff
[modules] When emitting line tables, only emit filenames that are actually referenced...
authorRichard Smith <richard-llvm@metafoo.co.uk>
Tue, 1 Sep 2015 07:41:55 +0000 (07:41 +0000)
committerRichard Smith <richard-llvm@metafoo.co.uk>
Tue, 1 Sep 2015 07:41:55 +0000 (07:41 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@246534 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Serialization/ASTReader.cpp
lib/Serialization/ASTWriter.cpp

index 1d692c8d7f438e31d1107d014541b89402ade52d..f4044624d07d321a364ba9010160e81745e59363 100644 (file)
@@ -1058,11 +1058,12 @@ bool ASTReader::ParseLineTable(ModuleFile &F,
 
   // Parse the file names
   std::map<int, int> FileIDs;
-  for (int I = 0, N = Record[Idx++]; I != N; ++I) {
+  for (unsigned I = 0; Record[Idx]; ++I) {
     // Extract the file name
     auto Filename = ReadPath(F, Record, Idx);
     FileIDs[I] = LineTable.getLineTableFilenameID(Filename);
   }
+  ++Idx;
 
   // Parse the line entries
   std::vector<LineEntry> Entries;
@@ -1074,7 +1075,7 @@ bool ASTReader::ParseLineTable(ModuleFile &F,
 
     // Extract the line entries
     unsigned NumEntries = Record[Idx++];
-    assert(NumEntries && "Numentries is 00000");
+    assert(NumEntries && "no line entries for file ID");
     Entries.clear();
     Entries.reserve(NumEntries);
     for (unsigned I = 0; I != NumEntries; ++I) {
index 0349378076c3376d96a153ed223f0137a30429ca..225a00c942f0cf7f169f7aa2858b36f99f47e21c 100644 (file)
@@ -1981,10 +1981,19 @@ void ASTWriter::WriteSourceManagerBlock(SourceManager &SourceMgr,
     LineTableInfo &LineTable = SourceMgr.getLineTable();
 
     Record.clear();
-    // Emit the file names.
-    Record.push_back(LineTable.getNumFilenames());
-    for (unsigned I = 0, N = LineTable.getNumFilenames(); I != N; ++I)
-      AddPath(LineTable.getFilename(I), Record);
+
+    // Emit the needed file names.
+    llvm::DenseMap<int, int> FilenameMap;
+    for (const auto &L : LineTable) {
+      if (L.first.ID < 0)
+        continue;
+      for (auto &LE : L.second) {
+        if (FilenameMap.insert(std::make_pair(LE.FilenameID,
+                                              FilenameMap.size())).second)
+          AddPath(LineTable.getFilename(LE.FilenameID), Record);
+      }
+    }
+    Record.push_back(0);
 
     // Emit the line entries
     for (LineTableInfo::iterator L = LineTable.begin(), LEnd = LineTable.end();
@@ -2003,11 +2012,12 @@ void ASTWriter::WriteSourceManagerBlock(SourceManager &SourceMgr,
            LE != LEEnd; ++LE) {
         Record.push_back(LE->FileOffset);
         Record.push_back(LE->LineNo);
-        Record.push_back(LE->FilenameID);
+        Record.push_back(FilenameMap[LE->FilenameID]);
         Record.push_back((unsigned)LE->FileKind);
         Record.push_back(LE->IncludeOffset);
       }
     }
+
     Stream.EmitRecord(SOURCE_MANAGER_LINE_TABLE, Record);
   }
 }