jansvoboda11 updated this revision to Diff 370257. jansvoboda11 added a comment.
Reorder patches. Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D108976/new/ https://reviews.llvm.org/D108976 Files: clang/include/clang/Tooling/Tooling.h clang/lib/Tooling/Tooling.cpp Index: clang/lib/Tooling/Tooling.cpp =================================================================== --- clang/lib/Tooling/Tooling.cpp +++ clang/lib/Tooling/Tooling.cpp @@ -343,10 +343,17 @@ for (const std::string &Str : CommandLine) Argv.push_back(Str.c_str()); const char *const BinaryName = Argv[0]; - IntrusiveRefCntPtr<DiagnosticOptions> DiagOpts = - CreateAndPopulateDiagOpts(Argv); - TextDiagnosticPrinter DiagnosticPrinter( - llvm::errs(), &*DiagOpts); + + // Parse diagnostic options from the driver command-line only if none were + // explicitly set. + IntrusiveRefCntPtr<DiagnosticOptions> ParsedDiagOpts; + DiagnosticOptions *DiagOpts = this->DiagOpts; + if (!DiagOpts) { + ParsedDiagOpts = CreateAndPopulateDiagOpts(Argv); + DiagOpts = &*ParsedDiagOpts; + } + + TextDiagnosticPrinter DiagnosticPrinter(llvm::errs(), DiagOpts); DiagnosticsEngine Diagnostics( IntrusiveRefCntPtr<DiagnosticIDs>(new DiagnosticIDs()), &*DiagOpts, DiagConsumer ? DiagConsumer : &DiagnosticPrinter, false); Index: clang/include/clang/Tooling/Tooling.h =================================================================== --- clang/include/clang/Tooling/Tooling.h +++ clang/include/clang/Tooling/Tooling.h @@ -268,11 +268,17 @@ ~ToolInvocation(); - /// Set a \c DiagnosticConsumer to use during parsing. + /// Set a \c DiagnosticConsumer to use during driver command-line parsing and + /// the action invocation itself. void setDiagnosticConsumer(DiagnosticConsumer *DiagConsumer) { this->DiagConsumer = DiagConsumer; } + /// Set a \c DiagnosticOptions to use during driver command-line parsing. + void setDiagnosticOptions(DiagnosticOptions *DiagOpts) { + this->DiagOpts = DiagOpts; + } + /// Run the clang invocation. /// /// \returns True if there were no errors during execution. @@ -290,6 +296,7 @@ FileManager *Files; std::shared_ptr<PCHContainerOperations> PCHContainerOps; DiagnosticConsumer *DiagConsumer = nullptr; + DiagnosticOptions *DiagOpts = nullptr; }; /// Utility to run a FrontendAction over a set of files.
Index: clang/lib/Tooling/Tooling.cpp =================================================================== --- clang/lib/Tooling/Tooling.cpp +++ clang/lib/Tooling/Tooling.cpp @@ -343,10 +343,17 @@ for (const std::string &Str : CommandLine) Argv.push_back(Str.c_str()); const char *const BinaryName = Argv[0]; - IntrusiveRefCntPtr<DiagnosticOptions> DiagOpts = - CreateAndPopulateDiagOpts(Argv); - TextDiagnosticPrinter DiagnosticPrinter( - llvm::errs(), &*DiagOpts); + + // Parse diagnostic options from the driver command-line only if none were + // explicitly set. + IntrusiveRefCntPtr<DiagnosticOptions> ParsedDiagOpts; + DiagnosticOptions *DiagOpts = this->DiagOpts; + if (!DiagOpts) { + ParsedDiagOpts = CreateAndPopulateDiagOpts(Argv); + DiagOpts = &*ParsedDiagOpts; + } + + TextDiagnosticPrinter DiagnosticPrinter(llvm::errs(), DiagOpts); DiagnosticsEngine Diagnostics( IntrusiveRefCntPtr<DiagnosticIDs>(new DiagnosticIDs()), &*DiagOpts, DiagConsumer ? DiagConsumer : &DiagnosticPrinter, false); Index: clang/include/clang/Tooling/Tooling.h =================================================================== --- clang/include/clang/Tooling/Tooling.h +++ clang/include/clang/Tooling/Tooling.h @@ -268,11 +268,17 @@ ~ToolInvocation(); - /// Set a \c DiagnosticConsumer to use during parsing. + /// Set a \c DiagnosticConsumer to use during driver command-line parsing and + /// the action invocation itself. void setDiagnosticConsumer(DiagnosticConsumer *DiagConsumer) { this->DiagConsumer = DiagConsumer; } + /// Set a \c DiagnosticOptions to use during driver command-line parsing. + void setDiagnosticOptions(DiagnosticOptions *DiagOpts) { + this->DiagOpts = DiagOpts; + } + /// Run the clang invocation. /// /// \returns True if there were no errors during execution. @@ -290,6 +296,7 @@ FileManager *Files; std::shared_ptr<PCHContainerOperations> PCHContainerOps; DiagnosticConsumer *DiagConsumer = nullptr; + DiagnosticOptions *DiagOpts = nullptr; }; /// Utility to run a FrontendAction over a set of files.
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits