[flang-commits] [flang] e8af247 - [Flang][Driver] Add warning support for invalid R_Group options

Victor Kingi via flang-commits flang-commits at lists.llvm.org
Thu Aug 31 05:09:30 PDT 2023


Author: Victor Kingi
Date: 2023-08-31T12:09:22Z
New Revision: e8af24736ada1ecc2495ada73225370be8a551a5

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

LOG: [Flang][Driver] Add warning support for invalid R_Group options

With the R_Group options, invalid values e.g. '-Rpa' will not emit
a warning like clang. This patch enables warning reporting, as
well as suggestions on what option the user intended to select.

Depends on D158174 and D158436. The former, adds backend
support to R_Group options while the latter, implements
regex support with some tests refactoring that cause a merge
conflict.

Reviewed By: awarzynski

Differential Revision: https://reviews.llvm.org/D158593

Added: 
    

Modified: 
    flang/lib/FrontendTool/ExecuteCompilerInvocation.cpp
    flang/test/Driver/optimization-remark-invalid.f90

Removed: 
    


################################################################################
diff  --git a/flang/lib/FrontendTool/ExecuteCompilerInvocation.cpp b/flang/lib/FrontendTool/ExecuteCompilerInvocation.cpp
index d16aff84f445fb..bc09dec17b7ae3 100644
--- a/flang/lib/FrontendTool/ExecuteCompilerInvocation.cpp
+++ b/flang/lib/FrontendTool/ExecuteCompilerInvocation.cpp
@@ -101,6 +101,18 @@ createFrontendAction(CompilerInstance &ci) {
   llvm_unreachable("Invalid program action!");
 }
 
+static void emitUnknownDiagWarning(clang::DiagnosticsEngine &diags,
+                                   clang::diag::Flavor flavor,
+                                   llvm::StringRef prefix,
+                                   llvm::StringRef opt) {
+  llvm::StringRef suggestion =
+      clang::DiagnosticIDs::getNearestOption(flavor, opt);
+  diags.Report(clang::diag::warn_unknown_diag_option)
+      << (flavor == clang::diag::Flavor::WarningOrError ? 0 : 1)
+      << (prefix.str() += std::string(opt)) << !suggestion.empty()
+      << (prefix.str() += std::string(suggestion));
+}
+
 // 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
@@ -123,6 +135,13 @@ updateDiagEngineForOptRemarks(clang::DiagnosticsEngine &diagsEng,
     if (!isPositive)
       remarkOpt = remarkOpt.substr(3);
 
+    // Verify that this is a valid optimization remarks option
+    if (diagIDs->getDiagnosticsInGroup(flavor, remarkOpt, diags)) {
+      emitUnknownDiagWarning(diagsEng, flavor, isPositive ? "-R" : "-Rno-",
+                             remarkOpt);
+      return;
+    }
+
     diagsEng.setSeverityForGroup(flavor, remarkOpt,
                                  isPositive ? clang::diag::Severity::Remark
                                             : clang::diag::Severity::Ignored);

diff  --git a/flang/test/Driver/optimization-remark-invalid.f90 b/flang/test/Driver/optimization-remark-invalid.f90
index 829ccba8951997..a57be4ec3e729d 100644
--- a/flang/test/Driver/optimization-remark-invalid.f90
+++ b/flang/test/Driver/optimization-remark-invalid.f90
@@ -5,8 +5,15 @@
 ! Check error on invalid regex -Rpass message is emitted
 ! RUN: not %flang %s -O1 -Rpass=[ -c 2>&1 | FileCheck %s --check-prefix=REGEX-INVALID
 
+! Check "unknown remark option" warning
+! RUN: %flang %s -O1 -R -c 2>&1 | FileCheck %s --check-prefix=WARN
+
+! Check "unknown remark option" warning with suggestion
+! RUN: %flang %s -O1 -Rpas -c 2>&1 | FileCheck %s --check-prefix=WARN-SUGGEST
 
 ! REGEX-INVALID: error: in pattern '-Rpass=[': brackets ([ ]) not balanced
+! WARN: warning: unknown remark option '-R'
+! WARN-SUGGEST: warning: unknown remark option '-Rpas'; did you mean '-Rpass'?
 
 program forttest
 end program forttest


        


More information about the flang-commits mailing list