Skip to content

Commit e8af247

Browse files
committed
[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
1 parent ac2d265 commit e8af247

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

flang/lib/FrontendTool/ExecuteCompilerInvocation.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,18 @@ createFrontendAction(CompilerInstance &ci) {
101101
llvm_unreachable("Invalid program action!");
102102
}
103103

104+
static void emitUnknownDiagWarning(clang::DiagnosticsEngine &diags,
105+
clang::diag::Flavor flavor,
106+
llvm::StringRef prefix,
107+
llvm::StringRef opt) {
108+
llvm::StringRef suggestion =
109+
clang::DiagnosticIDs::getNearestOption(flavor, opt);
110+
diags.Report(clang::diag::warn_unknown_diag_option)
111+
<< (flavor == clang::diag::Flavor::WarningOrError ? 0 : 1)
112+
<< (prefix.str() += std::string(opt)) << !suggestion.empty()
113+
<< (prefix.str() += std::string(suggestion));
114+
}
115+
104116
// Remarks are ignored by default in Diagnostic.td, hence, we have to
105117
// enable them here before execution. Clang follows same idea using
106118
// ProcessWarningOptions in Warnings.cpp
@@ -123,6 +135,13 @@ updateDiagEngineForOptRemarks(clang::DiagnosticsEngine &diagsEng,
123135
if (!isPositive)
124136
remarkOpt = remarkOpt.substr(3);
125137

138+
// Verify that this is a valid optimization remarks option
139+
if (diagIDs->getDiagnosticsInGroup(flavor, remarkOpt, diags)) {
140+
emitUnknownDiagWarning(diagsEng, flavor, isPositive ? "-R" : "-Rno-",
141+
remarkOpt);
142+
return;
143+
}
144+
126145
diagsEng.setSeverityForGroup(flavor, remarkOpt,
127146
isPositive ? clang::diag::Severity::Remark
128147
: clang::diag::Severity::Ignored);

flang/test/Driver/optimization-remark-invalid.f90

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,15 @@
55
! Check error on invalid regex -Rpass message is emitted
66
! RUN: not %flang %s -O1 -Rpass=[ -c 2>&1 | FileCheck %s --check-prefix=REGEX-INVALID
77

8+
! Check "unknown remark option" warning
9+
! RUN: %flang %s -O1 -R -c 2>&1 | FileCheck %s --check-prefix=WARN
10+
11+
! Check "unknown remark option" warning with suggestion
12+
! RUN: %flang %s -O1 -Rpas -c 2>&1 | FileCheck %s --check-prefix=WARN-SUGGEST
813

914
! REGEX-INVALID: error: in pattern '-Rpass=[': brackets ([ ]) not balanced
15+
! WARN: warning: unknown remark option '-R'
16+
! WARN-SUGGEST: warning: unknown remark option '-Rpas'; did you mean '-Rpass'?
1017

1118
program forttest
1219
end program forttest

0 commit comments

Comments
 (0)