Author: ibiryukov Date: Wed May 22 05:50:01 2019 New Revision: 361376 URL: http://llvm.org/viewvc/llvm-project?rev=361376&view=rev Log: [Frontend] Return an error on bad inputs to PrecompiledPreabmle
Summary: Instead of failing with assertions. Fixes a crash found by oss-fuzz: https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=12865 Reviewers: sammccall Reviewed By: sammccall Subscribers: cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D62137 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=361376&r1=361375&r2=361376&view=diff ============================================================================== --- cfe/trunk/include/clang/Frontend/PrecompiledPreamble.h (original) +++ cfe/trunk/include/clang/Frontend/PrecompiledPreamble.h Wed May 22 05:50:01 2019 @@ -291,7 +291,8 @@ enum class BuildPreambleError { CouldntCreateTempFile = 1, CouldntCreateTargetInfo, BeginSourceFileFailed, - CouldntEmitPCH + CouldntEmitPCH, + BadInputs }; class BuildPreambleErrorCategory final : public std::error_category { Modified: cfe/trunk/lib/Frontend/ASTUnit.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/ASTUnit.cpp?rev=361376&r1=361375&r2=361376&view=diff ============================================================================== --- cfe/trunk/lib/Frontend/ASTUnit.cpp (original) +++ cfe/trunk/lib/Frontend/ASTUnit.cpp Wed May 22 05:50:01 2019 @@ -1368,6 +1368,7 @@ ASTUnit::getMainBufferWithPrecompiledPre case BuildPreambleError::CouldntCreateTargetInfo: case BuildPreambleError::BeginSourceFileFailed: case BuildPreambleError::CouldntEmitPCH: + case BuildPreambleError::BadInputs: // These erros are more likely to repeat, retry after some period. PreambleRebuildCountdown = DefaultPreambleRebuildInterval; return nullptr; Modified: cfe/trunk/lib/Frontend/PrecompiledPreamble.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/PrecompiledPreamble.cpp?rev=361376&r1=361375&r2=361376&view=diff ============================================================================== --- cfe/trunk/lib/Frontend/PrecompiledPreamble.cpp (original) +++ cfe/trunk/lib/Frontend/PrecompiledPreamble.cpp Wed May 22 05:50:01 2019 @@ -299,14 +299,13 @@ llvm::ErrorOr<PrecompiledPreamble> Preco // created. This complexity should be lifted elsewhere. Clang->getTarget().adjust(Clang->getLangOpts()); - assert(Clang->getFrontendOpts().Inputs.size() == 1 && - "Invocation must have exactly one source file!"); - assert(Clang->getFrontendOpts().Inputs[0].getKind().getFormat() == - InputKind::Source && - "FIXME: AST inputs not yet supported here!"); - assert(Clang->getFrontendOpts().Inputs[0].getKind().getLanguage() != - InputKind::LLVM_IR && - "IR inputs not support here!"); + if (Clang->getFrontendOpts().Inputs.size() != 1 || + Clang->getFrontendOpts().Inputs[0].getKind().getFormat() != + InputKind::Source || + Clang->getFrontendOpts().Inputs[0].getKind().getLanguage() == + InputKind::LLVM_IR) { + return BuildPreambleError::BadInputs; + } // Clear out old caches and data. Diagnostics.Reset(); @@ -784,6 +783,8 @@ std::string BuildPreambleErrorCategory:: return "BeginSourceFile() return an error"; case BuildPreambleError::CouldntEmitPCH: return "Could not emit PCH"; + case BuildPreambleError::BadInputs: + return "Command line arguments must contain exactly one source file"; } llvm_unreachable("unexpected BuildPreambleError"); } _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits