diff --git a/flang/lib/Frontend/CompilerInvocation.cpp b/flang/lib/Frontend/CompilerInvocation.cpp --- a/flang/lib/Frontend/CompilerInvocation.cpp +++ b/flang/lib/Frontend/CompilerInvocation.cpp @@ -604,14 +604,24 @@ // TODO: Currently throws a Diagnostic for anything other than -W, // this has to change when other -W's are supported. if (args.hasArg(clang::driver::options::OPT_W_Joined)) { - if (args.getLastArgValue(clang::driver::options::OPT_W_Joined) - .equals("error")) { - res.setWarnAsErr(true); - } else { - const unsigned diagID = - diags.getCustomDiagID(clang::DiagnosticsEngine::Error, - "Only `-Werror` is supported currently."); - diags.Report(diagID); + const auto wArgs = + args.getAllArgValues(clang::driver::options::OPT_W_Joined); + for (const auto &wArg : wArgs) { + if (wArg == "error") { + res.setWarnAsErr(true); + } else if (wArg == "extra") { + const unsigned diagID = diags.getCustomDiagID( + clang::DiagnosticsEngine::Warning, + "Argument `-Wextra` was ignored during compilation. Only `-Werror` " + "is supported currently."); + diags.Report(diagID); + } else { + const unsigned diagID = + diags.getCustomDiagID(clang::DiagnosticsEngine::Error, + "Only `-Werror` is supported currently."); + diags.Report(diagID); + break; + } } } diff --git a/flang/test/Driver/werror-all.f90 b/flang/test/Driver/werror-all.f90 new file mode 100644 --- /dev/null +++ b/flang/test/Driver/werror-all.f90 @@ -0,0 +1,14 @@ +! Ensures that -Werror is read regardless of whether or not other -W +! flags are present in the CLI args + +! RUN: not %flang -std=f2018 -Werror -Wextra %s 2>&1 | FileCheck %s --check-prefix=WRONG +! RUN: %flang -std=f2018 -Wextra -Wall %s 2>&1 | FileCheck %s --check-prefix=CHECK-OK + +! WRONG: Semantic errors in +! CHECK-OK: FORALL index variable + +program werror_check_all + integer :: a(3) + forall (j=1:n) a(i) = 1 +end program werror_check_all + diff --git a/flang/test/Driver/wextra-ok.f90 b/flang/test/Driver/wextra-ok.f90 new file mode 100644 --- /dev/null +++ b/flang/test/Driver/wextra-ok.f90 @@ -0,0 +1,11 @@ +! Ensure that supplying -Wextra into flang-new does not raise error +! The first check should be changed if -Wextra is implemented + +! RUN: %flang -std=f2018 -Wextra %s 2>&1 | FileCheck %s --check-prefix=CHECK-OK +! RUN: not %flang -std=f2018 -Wblah -Wextra %s 2>&1 | FileCheck %s --check-prefix=WRONG + +! CHECK-OK: Argument `-Wextra` was ignored during compilation. Only `-Werror` is supported currently. +! WRONG: Only `-Werror` is supported currently. + +program wextra_ok +end program wextra_ok