Skip to content

Commit

Permalink
[Preamble] Empty preamble is not an error.
Browse files Browse the repository at this point in the history
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
  • Loading branch information
hokein committed Aug 17, 2018
1 parent 39a979c commit 70560ba
Show file tree
Hide file tree
Showing 3 changed files with 1 addition and 11 deletions.
3 changes: 1 addition & 2 deletions clang/include/clang/Frontend/PrecompiledPreamble.h
Original file line number Diff line number Diff line change
Expand Up @@ -286,8 +286,7 @@ class PreambleCallbacks {
};

enum class BuildPreambleError {
PreambleIsEmpty = 1,
CouldntCreateTempFile,
CouldntCreateTempFile = 1,
CouldntCreateTargetInfo,
BeginSourceFileFailed,
CouldntEmitPCH
Expand Down
1 change: 0 additions & 1 deletion clang/lib/Frontend/ASTUnit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1363,7 +1363,6 @@ ASTUnit::getMainBufferWithPrecompiledPreamble(
} else {
switch (static_cast<BuildPreambleError>(NewPreamble.getError().value())) {
case BuildPreambleError::CouldntCreateTempFile:
case BuildPreambleError::PreambleIsEmpty:
// Try again next time.
PreambleRebuildCounter = 1;
return nullptr;
Expand Down
8 changes: 0 additions & 8 deletions clang/lib/Frontend/PrecompiledPreamble.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -237,9 +237,6 @@ llvm::ErrorOr<PrecompiledPreamble> PrecompiledPreamble::Build(
PreambleCallbacks &Callbacks) {
assert(VFS && "VFS is null");

if (!Bounds.Size)
return BuildPreambleError::PreambleIsEmpty;

auto PreambleInvocation = std::make_shared<CompilerInvocation>(Invocation);
FrontendOptions &FrontendOpts = PreambleInvocation->getFrontendOpts();
PreprocessorOptions &PreprocessorOpts =
Expand Down Expand Up @@ -423,9 +420,6 @@ bool PrecompiledPreamble::CanReuse(const CompilerInvocation &Invocation,
PreprocessorOptions &PreprocessorOpts =
PreambleInvocation->getPreprocessorOpts();

if (!Bounds.Size)
return false;

// We've previously computed a preamble. Check whether we have the same
// preamble now that we did before, and that there's enough space in
// the main-file buffer within the precompiled preamble to fit the
Expand Down Expand Up @@ -758,8 +752,6 @@ const char *BuildPreambleErrorCategory::name() const noexcept {

std::string BuildPreambleErrorCategory::message(int condition) const {
switch (static_cast<BuildPreambleError>(condition)) {
case BuildPreambleError::PreambleIsEmpty:
return "Preamble is empty";
case BuildPreambleError::CouldntCreateTempFile:
return "Could not create temporary file for PCH";
case BuildPreambleError::CouldntCreateTargetInfo:
Expand Down

0 comments on commit 70560ba

Please sign in to comment.