diff options
author | Ilya Biryukov <ibiryukov@google.com> | 2019-08-27 10:02:18 +0000 |
---|---|---|
committer | Ilya Biryukov <ibiryukov@google.com> | 2019-08-27 10:02:18 +0000 |
commit | 999e4c4793fb8983011fbba3858c6c48b8c89248 (patch) | |
tree | 567fe211fbd1f6f31519ec1add8ce042f9d65740 /clang/lib/Frontend | |
parent | 7a2e21d9f4dc268837555c26fbaffa3675ea749e (diff) | |
download | bcm5719-llvm-999e4c4793fb8983011fbba3858c6c48b8c89248.tar.gz bcm5719-llvm-999e4c4793fb8983011fbba3858c6c48b8c89248.zip |
[Driver] Add an option for createInvocationFromCommandLine to recover on errors
Summary:
Previously, it would always return nullptr on any error.
This change adds a parameter, controlling whether the function should
attempt to return a non-null result even if unknown arguments (or other
errors were encountered).
The new behavior is only used in clangd.
Considered an alternative of changing the return value instead of adding
a new parameter, but that would require updating all callsites. Settled
with the parameter to minimize the code changes.
Reviewers: gribozavr
Reviewed By: gribozavr
Subscribers: nridge, jkorous, arphaman, kadircet, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D66731
llvm-svn: 370033
Diffstat (limited to 'clang/lib/Frontend')
-rw-r--r-- | clang/lib/Frontend/CreateInvocationFromCommandLine.cpp | 16 |
1 files changed, 5 insertions, 11 deletions
diff --git a/clang/lib/Frontend/CreateInvocationFromCommandLine.cpp b/clang/lib/Frontend/CreateInvocationFromCommandLine.cpp index d70a3b9a42d..ea7de7a4111 100644 --- a/clang/lib/Frontend/CreateInvocationFromCommandLine.cpp +++ b/clang/lib/Frontend/CreateInvocationFromCommandLine.cpp @@ -24,14 +24,9 @@ using namespace clang; using namespace llvm::opt; -/// createInvocationFromCommandLine - Construct a compiler invocation object for -/// a command line argument vector. -/// -/// \return A CompilerInvocation, or 0 if none was built for the given -/// argument vector. std::unique_ptr<CompilerInvocation> clang::createInvocationFromCommandLine( ArrayRef<const char *> ArgList, IntrusiveRefCntPtr<DiagnosticsEngine> Diags, - IntrusiveRefCntPtr<llvm::vfs::FileSystem> VFS) { + IntrusiveRefCntPtr<llvm::vfs::FileSystem> VFS, bool ShouldRecoverOnErorrs) { if (!Diags.get()) { // No diagnostics engine was provided, so create our own diagnostics object // with the default options. @@ -95,11 +90,10 @@ std::unique_ptr<CompilerInvocation> clang::createInvocationFromCommandLine( const ArgStringList &CCArgs = Cmd.getArguments(); auto CI = std::make_unique<CompilerInvocation>(); - if (!CompilerInvocation::CreateFromArgs(*CI, - const_cast<const char **>(CCArgs.data()), - const_cast<const char **>(CCArgs.data()) + - CCArgs.size(), - *Diags)) + if (!CompilerInvocation::CreateFromArgs( + *CI, const_cast<const char **>(CCArgs.data()), + const_cast<const char **>(CCArgs.data()) + CCArgs.size(), *Diags) && + !ShouldRecoverOnErorrs) return nullptr; return CI; } |