]> granicus.if.org Git - clang/commitdiff
[Preamble] Empty preamble is not an error.
authorHaojian Wu <hokein@google.com>
Fri, 17 Aug 2018 14:25:10 +0000 (14:25 +0000)
committerHaojian Wu <hokein@google.com>
Fri, 17 Aug 2018 14:25:10 +0000 (14:25 +0000)
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

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@340029 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Frontend/PrecompiledPreamble.h
lib/Frontend/ASTUnit.cpp
lib/Frontend/PrecompiledPreamble.cpp

index 6abdbe3a1e1b1e03a4f42f773928de744cd3678a..e2855fbdf26ea0ed611bfd140795222a595d543d 100644 (file)
@@ -286,8 +286,7 @@ public:
 };
 
 enum class BuildPreambleError {
-  PreambleIsEmpty = 1,
-  CouldntCreateTempFile,
+  CouldntCreateTempFile = 1,
   CouldntCreateTargetInfo,
   BeginSourceFileFailed,
   CouldntEmitPCH
index e4c313fed30f80a1b7769c4f8c6c27d194ed8a0a..701f07f22e37f1017e465ccb6bbd547334047a11 100644 (file)
@@ -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;
index 30ae2db26d86246a89097056b8c9865b00665626..4bff339711d0405493316ca90c68ce677db4bb81 100644 (file)
@@ -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 =
@@ -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
@@ -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: