summaryrefslogtreecommitdiff
path: root/clang-tools-extra/clangd/ClangdUnit.cpp
diff options
context:
space:
mode:
authorIlya Biryukov <ibiryukov@google.com>2018-02-09 13:51:57 +0000
committerIlya Biryukov <ibiryukov@google.com>2018-02-09 13:51:57 +0000
commite1d04c8f8dc7e4863050424a6e91d4c04620549b (patch)
tree26b55736775cb99dc809df8ef78fd41e5fa37472 /clang-tools-extra/clangd/ClangdUnit.cpp
parente364aa57d7d31a50dc67d46b404e2e350feeb7bf (diff)
[clangd] Fix crash when CompilerInvocation can't be created.
Summary: This can happen if the CompileCommand provided by compilation database is malformed. Reviewers: hokein, ioeric, sammccall Reviewed By: sammccall Subscribers: klimek, jkorous-apple, cfe-commits Differential Revision: https://reviews.llvm.org/D43122
Diffstat (limited to 'clang-tools-extra/clangd/ClangdUnit.cpp')
-rw-r--r--clang-tools-extra/clangd/ClangdUnit.cpp7
1 files changed, 6 insertions, 1 deletions
diff --git a/clang-tools-extra/clangd/ClangdUnit.cpp b/clang-tools-extra/clangd/ClangdUnit.cpp
index c16c218fbae..d7a8e89faab 100644
--- a/clang-tools-extra/clangd/ClangdUnit.cpp
+++ b/clang-tools-extra/clangd/ClangdUnit.cpp
@@ -405,10 +405,15 @@ CppFile::rebuild(ParseInputs &&Inputs) {
&IgnoreDiagnostics, false);
CI = createInvocationFromCommandLine(ArgStrs, CommandLineDiagsEngine,
Inputs.FS);
+ if (!CI) {
+ log("Could not build CompilerInvocation for file " + FileName);
+ AST = llvm::None;
+ Preamble = nullptr;
+ return llvm::None;
+ }
// createInvocationFromCommandLine sets DisableFree.
CI->getFrontendOpts().DisableFree = false;
}
- assert(CI && "Couldn't create CompilerInvocation");
std::unique_ptr<llvm::MemoryBuffer> ContentsBuffer =
llvm::MemoryBuffer::getMemBufferCopy(Inputs.Contents, FileName);