[clang-tools-extra] f4b0ebb - Revert "clang-tidy and clang-query wont crash with invalid command line options"

Nathan James via cfe-commits cfe-commits at lists.llvm.org
Sun May 31 08:40:23 PDT 2020


Author: Nathan James
Date: 2020-05-31T16:40:09+01:00
New Revision: f4b0ebb89b3086a2bdd8c7dd1f5d142fa09ca728

URL: https://github.com/llvm/llvm-project/commit/f4b0ebb89b3086a2bdd8c7dd1f5d142fa09ca728
DIFF: https://github.com/llvm/llvm-project/commit/f4b0ebb89b3086a2bdd8c7dd1f5d142fa09ca728.diff

LOG: Revert "clang-tidy and clang-query wont crash with invalid command line options"

This reverts commit f23ddbe3c3ae5f40b99ba272afc3d16b800ba8b9.

Added: 
    

Modified: 
    clang-tools-extra/clang-query/tool/ClangQuery.cpp
    clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp

Removed: 
    clang-tools-extra/test/clang-query/invalid-command-line.cpp
    clang-tools-extra/test/clang-tidy/infrastructure/invalid-command-line.cpp


################################################################################
diff  --git a/clang-tools-extra/clang-query/tool/ClangQuery.cpp b/clang-tools-extra/clang-query/tool/ClangQuery.cpp
index 0c471def2e14..5cfa0acf9120 100644
--- a/clang-tools-extra/clang-query/tool/ClangQuery.cpp
+++ b/clang-tools-extra/clang-query/tool/ClangQuery.cpp
@@ -35,7 +35,6 @@
 #include "llvm/Support/CommandLine.h"
 #include "llvm/Support/MemoryBuffer.h"
 #include "llvm/Support/Signals.h"
-#include "llvm/Support/WithColor.h"
 #include <fstream>
 #include <string>
 
@@ -87,14 +86,7 @@ bool runCommandsInFile(const char *ExeName, std::string const &FileName,
 int main(int argc, const char **argv) {
   llvm::sys::PrintStackTraceOnErrorSignal(argv[0]);
 
-  llvm::Expected<CommonOptionsParser> OptionsParser =
-      CommonOptionsParser::create(argc, argv, ClangQueryCategory,
-                                  llvm::cl::OneOrMore);
-
-  if (!OptionsParser) {
-    llvm::WithColor::error() << llvm::toString(OptionsParser.takeError());
-    return 1;
-  }
+  CommonOptionsParser OptionsParser(argc, argv, ClangQueryCategory);
 
   if (!Commands.empty() && !CommandFiles.empty()) {
     llvm::errs() << argv[0] << ": cannot specify both -c and -f\n";
@@ -107,8 +99,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;

diff  --git a/clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp b/clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp
index aca16b0d6d81..665d10026834 100644
--- a/clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp
+++ b/clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp
@@ -23,7 +23,6 @@
 #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;
@@ -334,14 +333,8 @@ getVfsFromFile(const std::string &OverlayFile,
 
 int clangTidyMain(int argc, const char **argv) {
   llvm::InitLLVM X(argc, argv);
-  llvm::Expected<CommonOptionsParser> OptionsParser =
-      CommonOptionsParser::create(argc, argv, ClangTidyCategory,
-                                  cl::ZeroOrMore);
-  if (!OptionsParser) {
-    llvm::WithColor::error() << llvm::toString(OptionsParser.takeError());
-    return 1;
-  }
-
+  CommonOptionsParser OptionsParser(argc, argv, ClangTidyCategory,
+                                    cl::ZeroOrMore);
   llvm::IntrusiveRefCntPtr<vfs::OverlayFileSystem> BaseFS(
       new vfs::OverlayFileSystem(vfs::getRealFileSystem()));
 
@@ -372,7 +365,7 @@ int clangTidyMain(int argc, const char **argv) {
   SmallString<256> ProfilePrefix = MakeAbsolute(StoreCheckProfile);
 
   StringRef FileName("dummy");
-  auto PathList = OptionsParser->getSourcePathList();
+  auto PathList = OptionsParser.getSourcePathList();
   if (!PathList.empty()) {
     FileName = PathList.front();
   }
@@ -440,7 +433,7 @@ int clangTidyMain(int argc, const char **argv) {
   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;

diff  --git a/clang-tools-extra/test/clang-query/invalid-command-line.cpp b/clang-tools-extra/test/clang-query/invalid-command-line.cpp
deleted file mode 100644
index 10ab43198b4e..000000000000
--- a/clang-tools-extra/test/clang-query/invalid-command-line.cpp
+++ /dev/null
@@ -1,4 +0,0 @@
-// RUN: not clang-query --invalid-arg 2>&1 | FileCheck %s
-
-// CHECK: error: [CommonOptionsParser]: clang-query: Unknown command line argument '--invalid-arg'.  Try: 'clang-query --help'
-// CHECK-NEXT: clang-query: Did you mean '--extra-arg'?

diff  --git a/clang-tools-extra/test/clang-tidy/infrastructure/invalid-command-line.cpp b/clang-tools-extra/test/clang-tidy/infrastructure/invalid-command-line.cpp
deleted file mode 100644
index 90b3f5200059..000000000000
--- a/clang-tools-extra/test/clang-tidy/infrastructure/invalid-command-line.cpp
+++ /dev/null
@@ -1,4 +0,0 @@
-// RUN: not clang-tidy --invalid-arg 2>&1 | FileCheck %s
-
-// CHECK: error: [CommonOptionsParser]: clang-tidy: Unknown command line argument '--invalid-arg'.  Try: 'clang-tidy --help'
-// CHECK-NEXT: clang-tidy: Did you mean '--extra-arg'?


        


More information about the cfe-commits mailing list