Author: hokein Date: Fri Aug 17 07:25:10 2018 New Revision: 340029 URL: http://llvm.org/viewvc/llvm-project?rev=340029&view=rev Log: [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 Modified: cfe/trunk/include/clang/Frontend/PrecompiledPreamble.h cfe/trunk/lib/Frontend/ASTUnit.cpp cfe/trunk/lib/Frontend/PrecompiledPreamble.cpp Modified: cfe/trunk/include/clang/Frontend/PrecompiledPreamble.h URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Frontend/PrecompiledPreamble.h?rev=340029&r1=340028&r2=340029&view=diff ============================================================================== --- cfe/trunk/include/clang/Frontend/PrecompiledPreamble.h (original) +++ cfe/trunk/include/clang/Frontend/PrecompiledPreamble.h Fri Aug 17 07:25:10 2018 @@ -286,8 +286,7 @@ public: }; enum class BuildPreambleError { - PreambleIsEmpty = 1, - CouldntCreateTempFile, + CouldntCreateTempFile = 1, CouldntCreateTargetInfo, BeginSourceFileFailed, CouldntEmitPCH Modified: cfe/trunk/lib/Frontend/ASTUnit.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/ASTUnit.cpp?rev=340029&r1=340028&r2=340029&view=diff ============================================================================== --- cfe/trunk/lib/Frontend/ASTUnit.cpp (original) +++ cfe/trunk/lib/Frontend/ASTUnit.cpp Fri Aug 17 07:25:10 2018 @@ -1363,7 +1363,6 @@ ASTUnit::getMainBufferWithPrecompiledPre } else { switch (static_cast<BuildPreambleError>(NewPreamble.getError().value())) { case BuildPreambleError::CouldntCreateTempFile: - case BuildPreambleError::PreambleIsEmpty: // Try again next time. PreambleRebuildCounter = 1; return nullptr; Modified: cfe/trunk/lib/Frontend/PrecompiledPreamble.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/PrecompiledPreamble.cpp?rev=340029&r1=340028&r2=340029&view=diff ============================================================================== --- cfe/trunk/lib/Frontend/PrecompiledPreamble.cpp (original) +++ cfe/trunk/lib/Frontend/PrecompiledPreamble.cpp Fri Aug 17 07:25:10 2018 @@ -237,9 +237,6 @@ llvm::ErrorOr<PrecompiledPreamble> Preco 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 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:: 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: _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits