diff options
author | Nathan James <n.james93@hotmail.co.uk> | 2020-05-31 17:41:29 +0100 |
---|---|---|
committer | Nathan James <n.james93@hotmail.co.uk> | 2020-05-31 17:41:29 +0100 |
commit | 5952125691571de9bd817551fb1baabe270e73f9 (patch) | |
tree | 204f1f9f8dec4309b44aa466aaedfb8c08bd6dcf /clang-tools-extra/clang-query | |
parent | f4b0ebb89b3086a2bdd8c7dd1f5d142fa09ca728 (diff) | |
download | llvm-5952125691571de9bd817551fb1baabe270e73f9.zip llvm-5952125691571de9bd817551fb1baabe270e73f9.tar.gz llvm-5952125691571de9bd817551fb1baabe270e73f9.tar.bz2 |
clang-tidy and clang-query wont crash with invalid command line options
Motivated by [[ https://bugs.llvm.org/show_bug.cgi?id=46141 | clang-tidy crashed for unknown command line argument. ]]
Reviewed By: aaron.ballman, thakis
Differential Revision: https://reviews.llvm.org/D80879
Diffstat (limited to 'clang-tools-extra/clang-query')
-rw-r--r-- | clang-tools-extra/clang-query/tool/ClangQuery.cpp | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/clang-tools-extra/clang-query/tool/ClangQuery.cpp b/clang-tools-extra/clang-query/tool/ClangQuery.cpp index 5cfa0ac..0c471de 100644 --- a/clang-tools-extra/clang-query/tool/ClangQuery.cpp +++ b/clang-tools-extra/clang-query/tool/ClangQuery.cpp @@ -35,6 +35,7 @@ #include "llvm/Support/CommandLine.h" #include "llvm/Support/MemoryBuffer.h" #include "llvm/Support/Signals.h" +#include "llvm/Support/WithColor.h" #include <fstream> #include <string> @@ -86,7 +87,14 @@ bool runCommandsInFile(const char *ExeName, std::string const &FileName, int main(int argc, const char **argv) { llvm::sys::PrintStackTraceOnErrorSignal(argv[0]); - CommonOptionsParser OptionsParser(argc, argv, ClangQueryCategory); + llvm::Expected<CommonOptionsParser> OptionsParser = + CommonOptionsParser::create(argc, argv, ClangQueryCategory, + llvm::cl::OneOrMore); + + if (!OptionsParser) { + llvm::WithColor::error() << llvm::toString(OptionsParser.takeError()); + return 1; + } if (!Commands.empty() && !CommandFiles.empty()) { llvm::errs() << argv[0] << ": cannot specify both -c and -f\n"; @@ -99,8 +107,8 @@ int main(int argc, const char **argv) { return 1; } - ClangTool Tool(OptionsParser.getCompilations(), - OptionsParser.getSourcePathList()); + ClangTool Tool(OptionsParser->getCompilations(), + OptionsParser->getSourcePathList()); std::vector<std::unique_ptr<ASTUnit>> ASTs; int Status = Tool.buildASTs(ASTs); int ASTStatus = 0; |