diff --git a/clang/include/clang/Basic/DiagnosticDriverKinds.td b/clang/include/clang/Basic/DiagnosticDriverKinds.td --- a/clang/include/clang/Basic/DiagnosticDriverKinds.td +++ b/clang/include/clang/Basic/DiagnosticDriverKinds.td @@ -113,6 +113,9 @@ def warn_drv_unsupported_option_for_flang : Warning< "the argument '%0' is not supported for option '%1'. Mapping to '%1%2'">, InGroup; +def warn_drv_unsupported_diag_option_for_flang : Warning< + "The warning option '-%0' is not supported">, + InGroup; def err_drv_invalid_thread_model_for_target : Error< "invalid thread model '%0' in '%1' for this target">; diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td --- a/clang/include/clang/Driver/Options.td +++ b/clang/include/clang/Driver/Options.td @@ -235,6 +235,10 @@ def clang_ignored_m_Group : OptionGroup<"">, Group, Flags<[Ignored]>; +// Unsupported flang groups +def flang_ignored_w_Group : OptionGroup<"">, + Group, Flags<[FlangOnlyOption, Ignored]>; + // Group for clang options in the process of deprecation. // Please include the version that deprecated the flag as comment to allow // easier garbage collection. @@ -4871,6 +4875,10 @@ def fno_#NAME : Flag<["-"], "fno-"#name>; } +multiclass FlangIgnoredDiagOpt { + def unsupported_warning_w#NAME : Flag<["-", "--"], "W"#name>, Group; +} + defm : BooleanFFlag<"keep-inline-functions">, Group; def fprofile_dir : Joined<["-"], "fprofile-dir=">, Group; @@ -5030,6 +5038,36 @@ defm sign_zero : BooleanFFlag<"sign-zero">, Group; defm whole_file : BooleanFFlag<"whole-file">, Group; +// -W options unsupported by the flang compiler +// If any of these options are passed into flang's compiler driver, +// a warning will be raised and the argument will be claimed +defm : FlangIgnoredDiagOpt<"extra">; +defm : FlangIgnoredDiagOpt<"aliasing">; +defm : FlangIgnoredDiagOpt<"ampersand">; +defm : FlangIgnoredDiagOpt<"array-bounds">; +defm : FlangIgnoredDiagOpt<"c-binding-type">; +defm : FlangIgnoredDiagOpt<"character-truncation">; +defm : FlangIgnoredDiagOpt<"conversion">; +defm : FlangIgnoredDiagOpt<"do-subscript">; +defm : FlangIgnoredDiagOpt<"function-elimination">; +defm : FlangIgnoredDiagOpt<"implicit-interface">; +defm : FlangIgnoredDiagOpt<"implicit-procedure">; +defm : FlangIgnoredDiagOpt<"intrinsic-shadow">; +defm : FlangIgnoredDiagOpt<"use-without-only">; +defm : FlangIgnoredDiagOpt<"intrinsics-std">; +defm : FlangIgnoredDiagOpt<"line-truncation">; +defm : FlangIgnoredDiagOpt<"no-align-commons">; +defm : FlangIgnoredDiagOpt<"no-overwrite-recursive">; +defm : FlangIgnoredDiagOpt<"no-tabs">; +defm : FlangIgnoredDiagOpt<"real-q-constant">; +defm : FlangIgnoredDiagOpt<"surprising">; +defm : FlangIgnoredDiagOpt<"underflow">; +defm : FlangIgnoredDiagOpt<"unused-parameter">; +defm : FlangIgnoredDiagOpt<"realloc-lhs">; +defm : FlangIgnoredDiagOpt<"realloc-lhs-all">; +defm : FlangIgnoredDiagOpt<"frontend-loop-interchange">; +defm : FlangIgnoredDiagOpt<"target-lifetime">; + // C++ SYCL options def fsycl : Flag<["-"], "fsycl">, Flags<[NoXarchOption, CoreOption]>, Group, HelpText<"Enables SYCL kernels compilation for device">; diff --git a/clang/lib/Driver/ToolChains/Flang.cpp b/clang/lib/Driver/ToolChains/Flang.cpp --- a/clang/lib/Driver/ToolChains/Flang.cpp +++ b/clang/lib/Driver/ToolChains/Flang.cpp @@ -329,6 +329,13 @@ A->render(Args, CmdArgs); } + // Remove any unsupported gfortran diagnostic options + for (const Arg *A : Args.filtered(options::OPT_flang_ignored_w_Group)) { + A->claim(); + D.Diag(diag::warn_drv_unsupported_diag_option_for_flang) + << A->getOption().getName(); + } + // Optimization level for CodeGen. if (const Arg *A = Args.getLastArg(options::OPT_O_Group)) { if (A->getOption().matches(options::OPT_O4)) { diff --git a/flang/docs/FlangDriver.md b/flang/docs/FlangDriver.md --- a/flang/docs/FlangDriver.md +++ b/flang/docs/FlangDriver.md @@ -581,6 +581,10 @@ GCC/GFortran will also set flush-to-zero mode: linking `crtfastmath.o`, the same as Flang. +The only GCC/GFortran warning option currently supported is `-Werror`. Passing +any unsupported GCC/GFortran warning flags into Flang's compiler driver will +result in warnings being emitted. + ### Comparison with nvfortran nvfortran defines `-fast` as `-O2 -Munroll=c:1 -Mnoframe -Mlre -Mpre -Mvect=simd -Mcache_align -Mflushz -Mvect`. 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 @@ -610,14 +610,17 @@ // 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 { + const unsigned diagID = + diags.getCustomDiagID(clang::DiagnosticsEngine::Error, + "Only `-Werror` is supported currently."); + diags.Report(diagID); + } } } diff --git a/flang/test/Driver/w-arg-unsupported.f90 b/flang/test/Driver/w-arg-unsupported.f90 new file mode 100644 --- /dev/null +++ b/flang/test/Driver/w-arg-unsupported.f90 @@ -0,0 +1,37 @@ +! RUN: %flang -std=f2018 -Wextra -Waliasing -Wampersand -Warray-bounds -Wc-binding-type \ +! RUN: -Wcharacter-truncation -Wconversion -Wdo-subscript -Wfunction-elimination \ +! RUN: -Wimplicit-interface -Wimplicit-procedure -Wintrinsic-shadow -Wuse-without-only \ +! RUN: -Wintrinsics-std -Wline-truncation -Wno-align-commons -Wno-overwrite-recursive \ +! RUN: -Wno-tabs -Wreal-q-constant -Wsurprising -Wunderflow -Wunused-parameter \ +! RUN: -Wrealloc-lhs -Wrealloc-lhs-all -Wfrontend-loop-interchange -Wtarget-lifetime %s \ +! RUN: 2>&1 | FileCheck %s + +! CHECK: The warning option '-Wextra' is not supported +! CHECK-NEXT: The warning option '-Waliasing' is not supported +! CHECK-NEXT: The warning option '-Wampersand' is not supported +! CHECK-NEXT: The warning option '-Warray-bounds' is not supported +! CHECK-NEXT: The warning option '-Wc-binding-type' is not supported +! CHECK-NEXT: The warning option '-Wcharacter-truncation' is not supported +! CHECK-NEXT: The warning option '-Wconversion' is not supported +! CHECK-NEXT: The warning option '-Wdo-subscript' is not supported +! CHECK-NEXT: The warning option '-Wfunction-elimination' is not supported +! CHECK-NEXT: The warning option '-Wimplicit-interface' is not supported +! CHECK-NEXT: The warning option '-Wimplicit-procedure' is not supported +! CHECK-NEXT: The warning option '-Wintrinsic-shadow' is not supported +! CHECK-NEXT: The warning option '-Wuse-without-only' is not supported +! CHECK-NEXT: The warning option '-Wintrinsics-std' is not supported +! CHECK-NEXT: The warning option '-Wline-truncation' is not supported +! CHECK-NEXT: The warning option '-Wno-align-commons' is not supported +! CHECK-NEXT: The warning option '-Wno-overwrite-recursive' is not supported +! CHECK-NEXT: The warning option '-Wno-tabs' is not supported +! CHECK-NEXT: The warning option '-Wreal-q-constant' is not supported +! CHECK-NEXT: The warning option '-Wsurprising' is not supported +! CHECK-NEXT: The warning option '-Wunderflow' is not supported +! CHECK-NEXT: The warning option '-Wunused-parameter' is not supported +! CHECK-NEXT: The warning option '-Wrealloc-lhs' is not supported +! CHECK-NEXT: The warning option '-Wrealloc-lhs-all' is not supported +! CHECK-NEXT: The warning option '-Wfrontend-loop-interchange' is not supported +! CHECK-NEXT: The warning option '-Wtarget-lifetime' is not supported + +program m +end program 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,13 @@ +! 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: The warning option '-Wextra' is not supported +! WRONG: Only `-Werror` is supported currently. + +program wextra_ok +end program wextra_ok