diff --git a/flang/lib/FrontendTool/ExecuteCompilerInvocation.cpp b/flang/lib/FrontendTool/ExecuteCompilerInvocation.cpp --- a/flang/lib/FrontendTool/ExecuteCompilerInvocation.cpp +++ b/flang/lib/FrontendTool/ExecuteCompilerInvocation.cpp @@ -101,6 +101,18 @@ 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,12 @@ if (!isPositive) remarkOpt = remarkOpt.substr(3); + 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.f90 b/flang/test/Driver/optimization-remark.f90 --- a/flang/test/Driver/optimization-remark.f90 +++ b/flang/test/Driver/optimization-remark.f90 @@ -11,6 +11,12 @@ ! RUN: %flang %s -O1 -Rno-pass-missed 2>&1 | FileCheck %s --allow-empty --check-prefix=NO-REMARKS ! RUN: %flang %s -O1 -Rno-pass-analysis 2>&1 | FileCheck %s --allow-empty --check-prefix=NO-REMARKS +! Check "unknown remark option" warning +! RUN: %flang %s -O1 -R 2>&1 | FileCheck %s --check-prefix=WARN + +! Check "unknown remark option" warning with suggestion +! RUN: %flang %s -O1 -Rpas 2>&1 | FileCheck %s --check-prefix=WARN-SUGGEST + ! Check full -Rpass message is emitted ! RUN: %flang %s -O1 -Rpass 2>&1 | FileCheck %s @@ -21,13 +27,15 @@ ! RUN: %flang %s -O1 -Rpass-analysis 2>&1 | FileCheck %s --check-prefix=REMARKS-ANALYSIS ! CHECK: remark: Loop deleted because it is invariant +! REMARKS: remark: +! NO-REMARKS-NOT: remark: ! REMARKS-MISSED: remark: loop not vectorized ! REMARKS-MISSED-NOT: instruction cannot be vectorized ! REMARKS-ANALYSIS: remark: loop not vectorized: instruction cannot be vectorized ! REMARKS-ANALYSIS-NOT: will not be inlined into {{.*}} because its definition is unavailable -! REMARKS: remark: -! NO-REMARKS-NOT: remark: +! WARN: warning: unknown remark option '-R' +! WARN-SUGGEST: warning: unknown remark option '-Rpas'; did you mean '-Rpass'? program forttest implicit none