ilya-biryukov created this revision. ilya-biryukov added a reviewer: sammccall. Herald added a project: clang.
Instead of failing with assertions. Fixed a crash found by oss-fuzz: https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=12865 Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D62137 Files: clang/include/clang/Frontend/PrecompiledPreamble.h clang/lib/Frontend/ASTUnit.cpp clang/lib/Frontend/PrecompiledPreamble.cpp Index: clang/lib/Frontend/PrecompiledPreamble.cpp =================================================================== --- clang/lib/Frontend/PrecompiledPreamble.cpp +++ clang/lib/Frontend/PrecompiledPreamble.cpp @@ -299,14 +299,13 @@ // 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(); @@ -770,6 +769,8 @@ 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"); } Index: clang/lib/Frontend/ASTUnit.cpp =================================================================== --- clang/lib/Frontend/ASTUnit.cpp +++ clang/lib/Frontend/ASTUnit.cpp @@ -1366,6 +1366,7 @@ case BuildPreambleError::CouldntCreateTargetInfo: case BuildPreambleError::BeginSourceFileFailed: case BuildPreambleError::CouldntEmitPCH: + case BuildPreambleError::BadInputs: // These erros are more likely to repeat, retry after some period. PreambleRebuildCounter = DefaultPreambleRebuildInterval; return nullptr; Index: clang/include/clang/Frontend/PrecompiledPreamble.h =================================================================== --- clang/include/clang/Frontend/PrecompiledPreamble.h +++ clang/include/clang/Frontend/PrecompiledPreamble.h @@ -291,7 +291,8 @@ CouldntCreateTempFile = 1, CouldntCreateTargetInfo, BeginSourceFileFailed, - CouldntEmitPCH + CouldntEmitPCH, + BadInputs }; class BuildPreambleErrorCategory final : public std::error_category {
Index: clang/lib/Frontend/PrecompiledPreamble.cpp =================================================================== --- clang/lib/Frontend/PrecompiledPreamble.cpp +++ clang/lib/Frontend/PrecompiledPreamble.cpp @@ -299,14 +299,13 @@ // 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(); @@ -770,6 +769,8 @@ 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"); } Index: clang/lib/Frontend/ASTUnit.cpp =================================================================== --- clang/lib/Frontend/ASTUnit.cpp +++ clang/lib/Frontend/ASTUnit.cpp @@ -1366,6 +1366,7 @@ case BuildPreambleError::CouldntCreateTargetInfo: case BuildPreambleError::BeginSourceFileFailed: case BuildPreambleError::CouldntEmitPCH: + case BuildPreambleError::BadInputs: // These erros are more likely to repeat, retry after some period. PreambleRebuildCounter = DefaultPreambleRebuildInterval; return nullptr; Index: clang/include/clang/Frontend/PrecompiledPreamble.h =================================================================== --- clang/include/clang/Frontend/PrecompiledPreamble.h +++ clang/include/clang/Frontend/PrecompiledPreamble.h @@ -291,7 +291,8 @@ CouldntCreateTempFile = 1, CouldntCreateTargetInfo, BeginSourceFileFailed, - CouldntEmitPCH + CouldntEmitPCH, + BadInputs }; class BuildPreambleErrorCategory final : public std::error_category {
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits