aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/Frontend/ASTUnit.cpp
diff options
context:
space:
mode:
authorNikolai Kosjar <nikolai.kosjar@qt.io>2019-05-21 07:26:59 +0000
committerNikolai Kosjar <nikolai.kosjar@qt.io>2019-05-21 07:26:59 +0000
commit295c19e948d29b33919a41792fff2ec7ba0c709b (patch)
tree243478d969d2b1b5b8cbf08bec7127965d105e8f /clang/lib/Frontend/ASTUnit.cpp
parent5f3deb9bb5a7a6d84d46f4567872899c1ae29860 (diff)
downloadllvm-295c19e948d29b33919a41792fff2ec7ba0c709b.zip
llvm-295c19e948d29b33919a41792fff2ec7ba0c709b.tar.gz
llvm-295c19e948d29b33919a41792fff2ec7ba0c709b.tar.bz2
[Preamble] Reuse preamble even if an unsaved file does not exist
When a preamble is created an unsaved file not existing on disk is already part of PrecompiledPreamble::FilesInPreamble. However, when checking whether the preamble can be re-used, a failed stat of such an unsaved file invalidated the preamble, which led to pointless and time consuming preamble regenerations on subsequent reparses. Do not require anymore that unsaved files should exist on disk. This avoids costly preamble invalidations depending on timing issues for the cases where the file on disk might be removed just to be regenerated a bit later. It also allows an IDE to provide in-memory files that might not exist on disk, e.g. because the build system hasn't generated those yet. Differential Revision: https://reviews.llvm.org/D41005 llvm-svn: 361226
Diffstat (limited to 'clang/lib/Frontend/ASTUnit.cpp')
-rw-r--r--clang/lib/Frontend/ASTUnit.cpp22
1 files changed, 12 insertions, 10 deletions
diff --git a/clang/lib/Frontend/ASTUnit.cpp b/clang/lib/Frontend/ASTUnit.cpp
index 221bf97c..95d1bf2 100644
--- a/clang/lib/Frontend/ASTUnit.cpp
+++ b/clang/lib/Frontend/ASTUnit.cpp
@@ -1304,22 +1304,22 @@ ASTUnit::getMainBufferWithPrecompiledPreamble(
PreambleInvocationIn.getDiagnosticOpts());
getDiagnostics().setNumWarnings(NumWarningsInPreamble);
- PreambleRebuildCounter = 1;
+ PreambleRebuildCountdown = 1;
return MainFileBuffer;
} else {
Preamble.reset();
PreambleDiagnostics.clear();
TopLevelDeclsInPreamble.clear();
PreambleSrcLocCache.clear();
- PreambleRebuildCounter = 1;
+ PreambleRebuildCountdown = 1;
}
}
// If the preamble rebuild counter > 1, it's because we previously
// failed to build a preamble and we're not yet ready to try
// again. Decrement the counter and return a failure.
- if (PreambleRebuildCounter > 1) {
- --PreambleRebuildCounter;
+ if (PreambleRebuildCountdown > 1) {
+ --PreambleRebuildCountdown;
return nullptr;
}
@@ -1329,6 +1329,8 @@ ASTUnit::getMainBufferWithPrecompiledPreamble(
if (!AllowRebuild)
return nullptr;
+ ++PreambleCounter;
+
SmallVector<StandaloneDiagnostic, 4> NewPreambleDiagsStandalone;
SmallVector<StoredDiagnostic, 4> NewPreambleDiags;
ASTUnitPreambleCallbacks Callbacks;
@@ -1356,18 +1358,18 @@ ASTUnit::getMainBufferWithPrecompiledPreamble(
if (NewPreamble) {
Preamble = std::move(*NewPreamble);
- PreambleRebuildCounter = 1;
+ PreambleRebuildCountdown = 1;
} else {
switch (static_cast<BuildPreambleError>(NewPreamble.getError().value())) {
case BuildPreambleError::CouldntCreateTempFile:
// Try again next time.
- PreambleRebuildCounter = 1;
+ PreambleRebuildCountdown = 1;
return nullptr;
case BuildPreambleError::CouldntCreateTargetInfo:
case BuildPreambleError::BeginSourceFileFailed:
case BuildPreambleError::CouldntEmitPCH:
// These erros are more likely to repeat, retry after some period.
- PreambleRebuildCounter = DefaultPreambleRebuildInterval;
+ PreambleRebuildCountdown = DefaultPreambleRebuildInterval;
return nullptr;
}
llvm_unreachable("unexpected BuildPreambleError");
@@ -1507,7 +1509,7 @@ ASTUnit *ASTUnit::LoadFromCompilerInvocationAction(
AST->OnlyLocalDecls = OnlyLocalDecls;
AST->CaptureDiagnostics = CaptureDiagnostics;
if (PrecompilePreambleAfterNParses > 0)
- AST->PreambleRebuildCounter = PrecompilePreambleAfterNParses;
+ AST->PreambleRebuildCountdown = PrecompilePreambleAfterNParses;
AST->TUKind = Action ? Action->getTranslationUnitKind() : TU_Complete;
AST->ShouldCacheCodeCompletionResults = CacheCodeCompletionResults;
AST->IncludeBriefCommentsInCodeCompletion
@@ -1641,7 +1643,7 @@ bool ASTUnit::LoadFromCompilerInvocation(
std::unique_ptr<llvm::MemoryBuffer> OverrideMainBuffer;
if (PrecompilePreambleAfterNParses > 0) {
- PreambleRebuildCounter = PrecompilePreambleAfterNParses;
+ PreambleRebuildCountdown = PrecompilePreambleAfterNParses;
OverrideMainBuffer =
getMainBufferWithPrecompiledPreamble(PCHContainerOps, *Invocation, VFS);
getDiagnostics().Reset();
@@ -1819,7 +1821,7 @@ bool ASTUnit::Reparse(std::shared_ptr<PCHContainerOperations> PCHContainerOps,
// If we have a preamble file lying around, or if we might try to
// build a precompiled preamble, do so now.
std::unique_ptr<llvm::MemoryBuffer> OverrideMainBuffer;
- if (Preamble || PreambleRebuildCounter > 0)
+ if (Preamble || PreambleRebuildCountdown > 0)
OverrideMainBuffer =
getMainBufferWithPrecompiledPreamble(PCHContainerOps, *Invocation, VFS);