[Tooling][clang-tools-extra] Consume CommonOptionsParser errors in tools (#193675)
Several LibTooling-based tools printed errors returned from CommonOptionsParser::create() directly. However, printing an `llvm::Error` does not consume it, so argument parsing failures such as unknown tool options could abort. This commit fixes the problem. Closes https://github.com/llvm/llvm-project/issues/183009
This commit is contained in:
@@ -102,7 +102,7 @@ int main(int argc, const char **argv) {
|
||||
auto ExpectedParser =
|
||||
tooling::CommonOptionsParser::create(argc, argv, ChangeNamespaceCategory);
|
||||
if (!ExpectedParser) {
|
||||
llvm::errs() << ExpectedParser.takeError();
|
||||
llvm::errs() << llvm::toString(ExpectedParser.takeError());
|
||||
return 1;
|
||||
}
|
||||
tooling::CommonOptionsParser &OptionsParser = ExpectedParser.get();
|
||||
|
||||
@@ -131,7 +131,7 @@ int main(int argc, const char **argv) {
|
||||
auto ExpectedParser =
|
||||
CommonOptionsParser::create(argc, argv, FindAllSymbolsCategory);
|
||||
if (!ExpectedParser) {
|
||||
llvm::errs() << ExpectedParser.takeError();
|
||||
llvm::errs() << llvm::toString(ExpectedParser.takeError());
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
@@ -264,7 +264,7 @@ int includeFixerMain(int argc, const char **argv) {
|
||||
auto ExpectedParser =
|
||||
tooling::CommonOptionsParser::create(argc, argv, IncludeFixerCategory);
|
||||
if (!ExpectedParser) {
|
||||
llvm::errs() << ExpectedParser.takeError();
|
||||
llvm::errs() << llvm::toString(ExpectedParser.takeError());
|
||||
return 1;
|
||||
}
|
||||
tooling::CommonOptionsParser &options = ExpectedParser.get();
|
||||
|
||||
@@ -99,7 +99,7 @@ int main(int argc, const char **argv) {
|
||||
auto ExpectedParser =
|
||||
tooling::CommonOptionsParser::create(argc, argv, ClangMoveCategory);
|
||||
if (!ExpectedParser) {
|
||||
llvm::errs() << ExpectedParser.takeError();
|
||||
llvm::errs() << llvm::toString(ExpectedParser.takeError());
|
||||
return 1;
|
||||
}
|
||||
tooling::CommonOptionsParser &OptionsParser = ExpectedParser.get();
|
||||
|
||||
@@ -53,7 +53,7 @@ int main(int argc, const char **argv) {
|
||||
auto ExpectedParser = tooling::CommonOptionsParser::create(
|
||||
argc, argv, ClangReorderFieldsCategory, cl::OneOrMore, Usage);
|
||||
if (!ExpectedParser) {
|
||||
llvm::errs() << ExpectedParser.takeError();
|
||||
llvm::errs() << llvm::toString(ExpectedParser.takeError());
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
@@ -337,9 +337,9 @@ Changes in existing checks
|
||||
|
||||
- Improved :doc:`cppcoreguidelines-missing-std-forward
|
||||
<clang-tidy/checks/cppcoreguidelines/missing-std-forward>` check:
|
||||
|
||||
|
||||
- Fixed false positive for constrained template parameters
|
||||
|
||||
|
||||
- Fixed false positive with ``std::forward`` in brace-init and paren-init
|
||||
lambda captures such as ``[t{std::forward<T>(t)}]``.
|
||||
|
||||
@@ -513,7 +513,7 @@ Changes in existing checks
|
||||
|
||||
- Fixed incorrect naming style application to C++17 structured bindings.
|
||||
|
||||
- Fixed a false positive where function templates could be diagnosed as generic
|
||||
- Fixed a false positive where function templates could be diagnosed as generic
|
||||
identifiers when `DefaultCase` was enabled.
|
||||
|
||||
- Improved :doc:`readability-implicit-bool-conversion
|
||||
@@ -581,6 +581,8 @@ Improvements to include-fixer
|
||||
Improvements to clang-include-fixer
|
||||
-----------------------------------
|
||||
|
||||
- Fixed crashes when command-line argument parsing failed at unknown tool options.
|
||||
|
||||
Improvements to modularize
|
||||
--------------------------
|
||||
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
// RUN: not clang-change-namespace --nonsense %s -- 2>&1 | FileCheck %s
|
||||
// CHECK: clang-change-namespace{{(\.exe)?}}: Unknown command line argument '--nonsense'
|
||||
|
||||
int main() { return 0; }
|
||||
@@ -0,0 +1,4 @@
|
||||
// RUN: not clang-include-fixer --nonsense %s -- 2>&1 | FileCheck %s
|
||||
// CHECK: clang-include-fixer{{(\.exe)?}}: Unknown command line argument '--nonsense'
|
||||
|
||||
int main() { return 0; }
|
||||
@@ -0,0 +1,4 @@
|
||||
// RUN: not find-all-symbols --nonsense %s -- 2>&1 | FileCheck %s
|
||||
// CHECK: find-all-symbols{{(\.exe)?}}: Unknown command line argument '--nonsense'
|
||||
|
||||
int main() { return 0; }
|
||||
@@ -0,0 +1,4 @@
|
||||
// RUN: not clang-move --nonsense %s -- 2>&1 | FileCheck %s
|
||||
// CHECK: clang-move{{(\.exe)?}}: Unknown command line argument '--nonsense'
|
||||
|
||||
int main() { return 0; }
|
||||
@@ -0,0 +1,4 @@
|
||||
// RUN: not clang-reorder-fields --nonsense %s -- 2>&1 | FileCheck %s
|
||||
// CHECK: clang-reorder-fields{{(\.exe)?}}: Unknown command line argument '--nonsense'
|
||||
|
||||
int main() { return 0; }
|
||||
@@ -57,7 +57,7 @@ namespace tooling {
|
||||
/// auto ExpectedParser =
|
||||
/// CommonOptionsParser::create(argc, argv, MyToolCategory);
|
||||
/// if (!ExpectedParser) {
|
||||
/// llvm::errs() << ExpectedParser.takeError();
|
||||
/// llvm::errs() << llvm::toString(ExpectedParser.takeError());
|
||||
/// return 1;
|
||||
/// }
|
||||
/// CommonOptionsParser& OptionsParser = ExpectedParser.get();
|
||||
|
||||
2
clang/test/Refactor/argument-parsing-error-no-abort.cpp
Normal file
2
clang/test/Refactor/argument-parsing-error-no-abort.cpp
Normal file
@@ -0,0 +1,2 @@
|
||||
// RUN: not clang-refactor --nonsense 2>&1 | FileCheck %s
|
||||
// CHECK: clang-refactor{{(\.exe)?}}: Unknown command line argument '--nonsense'
|
||||
4
clang/test/Tooling/argument-parsing-error-no-abort.cpp
Normal file
4
clang/test/Tooling/argument-parsing-error-no-abort.cpp
Normal file
@@ -0,0 +1,4 @@
|
||||
// RUN: not clang-check --nonsense %s -- 2>&1 | FileCheck %s
|
||||
// CHECK: clang-check{{(\.exe)?}}: Unknown command line argument '--nonsense'
|
||||
|
||||
int main() { return 0; }
|
||||
@@ -203,7 +203,7 @@ int main(int argc, const char **argv) {
|
||||
auto ExpectedParser =
|
||||
CommonOptionsParser::create(argc, argv, ClangCheckCategory);
|
||||
if (!ExpectedParser) {
|
||||
llvm::errs() << ExpectedParser.takeError();
|
||||
llvm::errs() << llvm::toString(ExpectedParser.takeError());
|
||||
return 1;
|
||||
}
|
||||
CommonOptionsParser &OptionsParser = ExpectedParser.get();
|
||||
|
||||
@@ -617,7 +617,7 @@ int main(int argc, const char **argv) {
|
||||
argc, argv, cl::getGeneralCategory(), cl::ZeroOrMore,
|
||||
"Clang-based refactoring tool for C, C++ and Objective-C");
|
||||
if (!ExpectedParser) {
|
||||
llvm::errs() << ExpectedParser.takeError();
|
||||
llvm::errs() << llvm::toString(ExpectedParser.takeError());
|
||||
return 1;
|
||||
}
|
||||
CommonOptionsParser &Options = ExpectedParser.get();
|
||||
|
||||
Reference in New Issue
Block a user