Skip to content

Commit bb6a881

Browse files
committed
Fix three related, wily issues with the recompilation of precompiled
preambles: - When we rebuild a precompiled preamble, make sure to disable skipping anything in the main file; we may have had leftover preamble-skipping values in the lexer, which leads to very empty preamble. This is a correctness issue. - When we rebuild a precompiled preamble, clear out any prior state in the Diagnostic object. Otherwise, we might think that there were errors when we were building the preamble itself, and therefore reject the resulting preamble. This is mainly a performance issue. - Don't remove old remappings when digging out the remapping for the main file. Having the old mappings around does not hurt in the common case (later remappings will just overwrite them), and is important when we fail to find a preamble: we don't want to have removed the remapping, because we'll need it later. llvm-svn: 116041
1 parent dd77477 commit bb6a881

File tree

1 file changed

+5
-14
lines changed

1 file changed

+5
-14
lines changed

clang/lib/Frontend/ASTUnit.cpp

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -787,7 +787,7 @@ bool ASTUnit::Parse(llvm::MemoryBuffer *OverrideMainBuffer) {
787787
// results yet, do so now.
788788
if (ShouldCacheCodeCompletionResults && CachedCompletionResults.empty())
789789
CacheCodeCompletionResults();
790-
790+
791791
return false;
792792

793793
error:
@@ -878,12 +878,6 @@ ASTUnit::ComputePreamble(CompilerInvocation &Invocation,
878878
return std::make_pair((llvm::MemoryBuffer*)0,
879879
std::make_pair(0, true));
880880
CreatedBuffer = true;
881-
882-
// Remove this remapping. We've captured the buffer already.
883-
M = PreprocessorOpts.eraseRemappedFile(M);
884-
E = PreprocessorOpts.remapped_file_end();
885-
if (M == E)
886-
break;
887881
}
888882
}
889883
}
@@ -905,12 +899,6 @@ ASTUnit::ComputePreamble(CompilerInvocation &Invocation,
905899
}
906900

907901
Buffer = const_cast<llvm::MemoryBuffer *>(M->second);
908-
909-
// Remove this remapping. We've captured the buffer already.
910-
M = PreprocessorOpts.eraseRemappedFile(M);
911-
E = PreprocessorOpts.remapped_file_buffer_end();
912-
if (M == E)
913-
break;
914902
}
915903
}
916904
}
@@ -1090,7 +1078,7 @@ llvm::MemoryBuffer *ASTUnit::getMainBufferWithPrecompiledPreamble(
10901078
// return now.
10911079
if (!AllowRebuild)
10921080
return 0;
1093-
1081+
10941082
// We can't reuse the previously-computed preamble. Build a new one.
10951083
Preamble.clear();
10961084
llvm::sys::Path(PreambleFile).eraseFromDisk();
@@ -1162,6 +1150,8 @@ llvm::MemoryBuffer *ASTUnit::getMainBufferWithPrecompiledPreamble(
11621150
FrontendOpts.ChainedPCH = true;
11631151
// FIXME: Generate the precompiled header into memory?
11641152
FrontendOpts.OutputFile = PreamblePCHPath;
1153+
PreprocessorOpts.PrecompiledPreambleBytes.first = 0;
1154+
PreprocessorOpts.PrecompiledPreambleBytes.second = false;
11651155

11661156
// Create the compiler instance to use for building the precompiled preamble.
11671157
CompilerInstance Clang;
@@ -1204,6 +1194,7 @@ llvm::MemoryBuffer *ASTUnit::getMainBufferWithPrecompiledPreamble(
12041194
"IR inputs not support here!");
12051195

12061196
// Clear out old caches and data.
1197+
getDiagnostics().Reset();
12071198
StoredDiagnostics.clear();
12081199
TopLevelDecls.clear();
12091200
TopLevelDeclsInPreamble.clear();

0 commit comments

Comments
 (0)