[PATCH] D80879: clang-tidy and clang-query wont crash with invalid command line options
Nathan James via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Sat May 30 14:18:42 PDT 2020
njames93 created this revision.
njames93 added reviewers: aaron.ballman, alexfh.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.
Motivated by clang-tidy crashed for unknown command line argument. <https://bugs.llvm.org/show_bug.cgi?id=46141>
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D80879
Files:
clang-tools-extra/clang-query/tool/ClangQuery.cpp
clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp
Index: clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp
===================================================================
--- clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp
+++ clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp
@@ -23,6 +23,7 @@
#include "llvm/Support/Process.h"
#include "llvm/Support/Signals.h"
#include "llvm/Support/TargetSelect.h"
+#include "llvm/Support/WithColor.h"
using namespace clang::ast_matchers;
using namespace clang::driver;
@@ -333,8 +334,14 @@
int clangTidyMain(int argc, const char **argv) {
llvm::InitLLVM X(argc, argv);
- CommonOptionsParser OptionsParser(argc, argv, ClangTidyCategory,
- cl::ZeroOrMore);
+ llvm::Expected<CommonOptionsParser> OptionsParser =
+ CommonOptionsParser::create(argc, argv, ClangTidyCategory,
+ cl::ZeroOrMore);
+ if (!OptionsParser) {
+ llvm::WithColor::error() << llvm::toString(OptionsParser.takeError());
+ return 1;
+ }
+
llvm::IntrusiveRefCntPtr<vfs::OverlayFileSystem> BaseFS(
new vfs::OverlayFileSystem(vfs::getRealFileSystem()));
@@ -365,7 +372,7 @@
SmallString<256> ProfilePrefix = MakeAbsolute(StoreCheckProfile);
StringRef FileName("dummy");
- auto PathList = OptionsParser.getSourcePathList();
+ auto PathList = OptionsParser->getSourcePathList();
if (!PathList.empty()) {
FileName = PathList.front();
}
@@ -433,7 +440,7 @@
ClangTidyContext Context(std::move(OwningOptionsProvider),
AllowEnablingAnalyzerAlphaCheckers);
std::vector<ClangTidyError> Errors =
- runClangTidy(Context, OptionsParser.getCompilations(), PathList, BaseFS,
+ runClangTidy(Context, OptionsParser->getCompilations(), PathList, BaseFS,
EnableCheckProfile, ProfilePrefix);
bool FoundErrors = llvm::find_if(Errors, [](const ClangTidyError &E) {
return E.DiagLevel == ClangTidyError::Error;
Index: clang-tools-extra/clang-query/tool/ClangQuery.cpp
===================================================================
--- clang-tools-extra/clang-query/tool/ClangQuery.cpp
+++ 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,13 @@
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);
+
+ 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 +106,8 @@
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;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D80879.267479.patch
Type: text/x-patch
Size: 3328 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20200530/82366bc3/attachment.bin>
More information about the cfe-commits
mailing list