diff options
author | Victor Kingi <victor.kingi@arm.com> | 2023-08-17 11:19:12 +0000 |
---|---|---|
committer | Victor Kingi <victor.kingi@arm.com> | 2023-08-23 10:19:56 +0000 |
commit | 91989c67483c37bbcee4404eea789e39dd3470d9 (patch) | |
tree | 53197f74e551a28f2cede3926f5fb6aa61de8bda /flang/lib/FrontendTool | |
parent | 8d24b7322ee55eb780fc8115bfa8af07b6ee66b7 (diff) | |
download | llvm-91989c67483c37bbcee4404eea789e39dd3470d9.zip llvm-91989c67483c37bbcee4404eea789e39dd3470d9.tar.gz llvm-91989c67483c37bbcee4404eea789e39dd3470d9.tar.bz2 |
[Flang][Driver] Implement OPT_R_Joined options
Add a BackendRemarkConsumer class, responsible for handling diagnostics
received from LLVM. The diagnostics being information on middle and
backend passes used or not used.
Clang by default has all remarks ignored but manually sets the severity of
`R_Group` to visible(`clang::diag::clang::Severity::Remark`). This patch does
the same for Flang.
Depends on D157410. That patch adds the R family of options to
`FlangOption` and `FC1Option` in
`clang/include/clang/Driver/Options.td`
Reviewed By: awarzynski
Differential Revision: https://reviews.llvm.org/D158174
Diffstat (limited to 'flang/lib/FrontendTool')
-rw-r--r-- | flang/lib/FrontendTool/ExecuteCompilerInvocation.cpp | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/flang/lib/FrontendTool/ExecuteCompilerInvocation.cpp b/flang/lib/FrontendTool/ExecuteCompilerInvocation.cpp index 883f109..e1de344 100644 --- a/flang/lib/FrontendTool/ExecuteCompilerInvocation.cpp +++ b/flang/lib/FrontendTool/ExecuteCompilerInvocation.cpp @@ -22,6 +22,7 @@ #include "mlir/IR/AsmState.h" #include "mlir/IR/MLIRContext.h" #include "mlir/Pass/PassManager.h" +#include "clang/Basic/DiagnosticFrontend.h" #include "clang/Driver/Options.h" #include "llvm/Option/OptTable.h" #include "llvm/Option/Option.h" @@ -100,6 +101,34 @@ createFrontendAction(CompilerInstance &ci) { llvm_unreachable("Invalid program action!"); } +// Remarks are ignored by default in Diagnostic.td, hence, we have to +// enable them here before execution. Clang follows same idea using +// ProcessWarningOptions in Warnings.cpp +// This function is also responsible for emitting early warnings for +// invalid -R options. +static void +updateDiagEngineForOptRemarks(clang::DiagnosticsEngine &diagsEng, + const clang::DiagnosticOptions &opts) { + llvm::SmallVector<clang::diag::kind, 10> diags; + const llvm::IntrusiveRefCntPtr<clang::DiagnosticIDs> diagIDs = + diagsEng.getDiagnosticIDs(); + + for (unsigned i = 0; i < opts.Remarks.size(); i++) { + llvm::StringRef remarkOpt = opts.Remarks[i]; + const auto flavor = clang::diag::Flavor::Remark; + + // Check to see if this opt starts with "no-", if so, this is a + // negative form of the option. + bool isPositive = !remarkOpt.startswith("no-"); + if (!isPositive) + remarkOpt = remarkOpt.substr(3); + + diagsEng.setSeverityForGroup(flavor, remarkOpt, + isPositive ? clang::diag::Severity::Remark + : clang::diag::Severity::Ignored); + } +} + bool executeCompilerInvocation(CompilerInstance *flang) { // Honor -help. if (flang->getFrontendOpts().showHelp) { @@ -165,6 +194,9 @@ bool executeCompilerInvocation(CompilerInstance *flang) { // Honor color diagnostics. flang->getDiagnosticOpts().ShowColors = flang->getFrontendOpts().showColors; + updateDiagEngineForOptRemarks(flang->getDiagnostics(), + flang->getDiagnosticOpts()); + // Create and execute the frontend action. std::unique_ptr<FrontendAction> act(createFrontendAction(*flang)); if (!act) |