Skip to content

Commit 70560ba

Browse files
committedAug 17, 2018
[Preamble] Empty preamble is not an error.
Summary: Empty preamble is valid for source file which doesn't have any preprocessor and #includes. This patch makes clang treat an empty preamble as a normal preamble. Check: ninja check-clang A testcase is added in https://reviews.llvm.org/D50627. Reviewers: ilya-biryukov Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D50628 llvm-svn: 340029
1 parent 39a979c commit 70560ba

File tree

3 files changed

+1
-11
lines changed

3 files changed

+1
-11
lines changed
 

‎clang/include/clang/Frontend/PrecompiledPreamble.h

+1-2
Original file line numberDiff line numberDiff line change
@@ -286,8 +286,7 @@ class PreambleCallbacks {
286286
};
287287

288288
enum class BuildPreambleError {
289-
PreambleIsEmpty = 1,
290-
CouldntCreateTempFile,
289+
CouldntCreateTempFile = 1,
291290
CouldntCreateTargetInfo,
292291
BeginSourceFileFailed,
293292
CouldntEmitPCH

‎clang/lib/Frontend/ASTUnit.cpp

-1
Original file line numberDiff line numberDiff line change
@@ -1363,7 +1363,6 @@ ASTUnit::getMainBufferWithPrecompiledPreamble(
13631363
} else {
13641364
switch (static_cast<BuildPreambleError>(NewPreamble.getError().value())) {
13651365
case BuildPreambleError::CouldntCreateTempFile:
1366-
case BuildPreambleError::PreambleIsEmpty:
13671366
// Try again next time.
13681367
PreambleRebuildCounter = 1;
13691368
return nullptr;

‎clang/lib/Frontend/PrecompiledPreamble.cpp

-8
Original file line numberDiff line numberDiff line change
@@ -237,9 +237,6 @@ llvm::ErrorOr<PrecompiledPreamble> PrecompiledPreamble::Build(
237237
PreambleCallbacks &Callbacks) {
238238
assert(VFS && "VFS is null");
239239

240-
if (!Bounds.Size)
241-
return BuildPreambleError::PreambleIsEmpty;
242-
243240
auto PreambleInvocation = std::make_shared<CompilerInvocation>(Invocation);
244241
FrontendOptions &FrontendOpts = PreambleInvocation->getFrontendOpts();
245242
PreprocessorOptions &PreprocessorOpts =
@@ -423,9 +420,6 @@ bool PrecompiledPreamble::CanReuse(const CompilerInvocation &Invocation,
423420
PreprocessorOptions &PreprocessorOpts =
424421
PreambleInvocation->getPreprocessorOpts();
425422

426-
if (!Bounds.Size)
427-
return false;
428-
429423
// We've previously computed a preamble. Check whether we have the same
430424
// preamble now that we did before, and that there's enough space in
431425
// the main-file buffer within the precompiled preamble to fit the
@@ -758,8 +752,6 @@ const char *BuildPreambleErrorCategory::name() const noexcept {
758752

759753
std::string BuildPreambleErrorCategory::message(int condition) const {
760754
switch (static_cast<BuildPreambleError>(condition)) {
761-
case BuildPreambleError::PreambleIsEmpty:
762-
return "Preamble is empty";
763755
case BuildPreambleError::CouldntCreateTempFile:
764756
return "Could not create temporary file for PCH";
765757
case BuildPreambleError::CouldntCreateTargetInfo:

0 commit comments

Comments
 (0)