diff options
author | serge-sans-paille <sguelton@redhat.com> | 2021-01-11 16:19:35 +0100 |
---|---|---|
committer | serge-sans-paille <sguelton@redhat.com> | 2021-01-29 10:15:06 +0100 |
commit | d47ee525f9e9289815db0864b03e866fc8e5ba01 (patch) | |
tree | 634e74557ef6c2fe521173deff50d5f6242ca267 /clang-tools-extra/clang-include-fixer | |
parent | cba2552bfec1c9d837f7285a743e9e12fa6b043e (diff) | |
download | llvm-d47ee525f9e9289815db0864b03e866fc8e5ba01.tar.gz |
[clang-tooling] Prevent llvm::fatal_error on invalid CLI option
Fail gracefully instead. Prevent further misuse by enforcing the factory builder
instead of the constructor.
Differential Revision: https://reviews.llvm.org/D94420
Diffstat (limited to 'clang-tools-extra/clang-include-fixer')
-rw-r--r-- | clang-tools-extra/clang-include-fixer/find-all-symbols/tool/FindAllSymbolsMain.cpp | 9 | ||||
-rw-r--r-- | clang-tools-extra/clang-include-fixer/tool/ClangIncludeFixer.cpp | 8 |
2 files changed, 15 insertions, 2 deletions
diff --git a/clang-tools-extra/clang-include-fixer/find-all-symbols/tool/FindAllSymbolsMain.cpp b/clang-tools-extra/clang-include-fixer/find-all-symbols/tool/FindAllSymbolsMain.cpp index 8508721bb85a..b2d0efecc206 100644 --- a/clang-tools-extra/clang-include-fixer/find-all-symbols/tool/FindAllSymbolsMain.cpp +++ b/clang-tools-extra/clang-include-fixer/find-all-symbols/tool/FindAllSymbolsMain.cpp @@ -128,7 +128,14 @@ bool Merge(llvm::StringRef MergeDir, llvm::StringRef OutputFile) { } // namespace find_all_symbols int main(int argc, const char **argv) { - CommonOptionsParser OptionsParser(argc, argv, FindAllSymbolsCategory); + auto ExpectedParser = + CommonOptionsParser::create(argc, argv, FindAllSymbolsCategory); + if (!ExpectedParser) { + llvm::errs() << ExpectedParser.takeError(); + return 1; + } + + CommonOptionsParser &OptionsParser = ExpectedParser.get(); ClangTool Tool(OptionsParser.getCompilations(), OptionsParser.getSourcePathList()); diff --git a/clang-tools-extra/clang-include-fixer/tool/ClangIncludeFixer.cpp b/clang-tools-extra/clang-include-fixer/tool/ClangIncludeFixer.cpp index 50a0c49ba647..3a11a22def19 100644 --- a/clang-tools-extra/clang-include-fixer/tool/ClangIncludeFixer.cpp +++ b/clang-tools-extra/clang-include-fixer/tool/ClangIncludeFixer.cpp @@ -263,7 +263,13 @@ void writeToJson(llvm::raw_ostream &OS, const IncludeFixerContext& Context) { } int includeFixerMain(int argc, const char **argv) { - tooling::CommonOptionsParser options(argc, argv, IncludeFixerCategory); + auto ExpectedParser = + tooling::CommonOptionsParser::create(argc, argv, IncludeFixerCategory); + if (!ExpectedParser) { + llvm::errs() << ExpectedParser.takeError(); + return 1; + } + tooling::CommonOptionsParser &options = ExpectedParser.get(); tooling::ClangTool tool(options.getCompilations(), options.getSourcePathList()); |