[flang-commits] [flang] ce3a1c5 - [flang] Handle unsupported warning flags
Ethan Luis McDonough via flang-commits
flang-commits at lists.llvm.org
Tue Feb 21 14:14:28 PST 2023
Author: Ethan Luis McDonough
Date: 2023-02-21T16:14:19-06:00
New Revision: ce3a1c59e18027e7d18a2a0a99e4bc81ccc03491
URL: https://github.com/llvm/llvm-project/commit/ce3a1c59e18027e7d18a2a0a99e4bc81ccc03491
DIFF: https://github.com/llvm/llvm-project/commit/ce3a1c59e18027e7d18a2a0a99e4bc81ccc03491.diff
LOG: [flang] Handle unsupported warning flags
This PR makes flang emit a warning when the user passes an unsupported gfortran warning flag in as a CLI arg. This PR also checks each `-W` argument instead of just looking at the last one passed in.
Reviewed By: awarzynski
Differential Revision: https://reviews.llvm.org/D143301
Added:
flang/test/Driver/w-arg-unsupported.f90
flang/test/Driver/werror-all.f90
flang/test/Driver/wextra-ok.f90
Modified:
clang/include/clang/Basic/DiagnosticDriverKinds.td
clang/include/clang/Driver/Options.td
clang/lib/Driver/ToolChains/Flang.cpp
flang/docs/FlangDriver.md
flang/lib/Frontend/CompilerInvocation.cpp
Removed:
################################################################################
diff --git a/clang/include/clang/Basic/DiagnosticDriverKinds.td b/clang/include/clang/Basic/DiagnosticDriverKinds.td
index 35325de4a34a4..77fb1e00585a0 100644
--- a/clang/include/clang/Basic/DiagnosticDriverKinds.td
+++ b/clang/include/clang/Basic/DiagnosticDriverKinds.td
@@ -113,6 +113,9 @@ def warn_drv_unsupported_option_for_target : Warning<
def warn_drv_unsupported_option_for_flang : Warning<
"the argument '%0' is not supported for option '%1'. Mapping to '%1%2'">,
InGroup<OptionIgnored>;
+def warn_drv_unsupported_diag_option_for_flang : Warning<
+ "The warning option '-%0' is not supported">,
+ InGroup<OptionIgnored>;
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
index a26af0af2c946..a25854daf6a1b 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -235,6 +235,10 @@ def clang_ignored_f_Group : OptionGroup<"<clang ignored f group>">,
def clang_ignored_m_Group : OptionGroup<"<clang ignored m group>">,
Group<m_Group>, Flags<[Ignored]>;
+// Unsupported flang groups
+def flang_ignored_w_Group : OptionGroup<"<flang ignored W group>">,
+ Group<W_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 @@ multiclass BooleanFFlag<string name> {
def fno_#NAME : Flag<["-"], "fno-"#name>;
}
+multiclass FlangIgnoredDiagOpt<string name> {
+ def unsupported_warning_w#NAME : Flag<["-", "--"], "W"#name>, Group<flang_ignored_w_Group>;
+}
+
defm : BooleanFFlag<"keep-inline-functions">, Group<clang_ignored_gcc_optimization_f_Group>;
def fprofile_dir : Joined<["-"], "fprofile-dir=">, Group<f_Group>;
@@ -5030,6 +5038,36 @@ defm second_underscore : BooleanFFlag<"second-underscore">, Group<gfortran_Group
defm sign_zero : BooleanFFlag<"sign-zero">, Group<gfortran_Group>;
defm whole_file : BooleanFFlag<"whole-file">, Group<gfortran_Group>;
+// -W <arg> 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<sycl_Group>, HelpText<"Enables SYCL kernels compilation for device">;
diff --git a/clang/lib/Driver/ToolChains/Flang.cpp b/clang/lib/Driver/ToolChains/Flang.cpp
index cd3907c099481..b50d2c5c4f8d2 100644
--- a/clang/lib/Driver/ToolChains/Flang.cpp
+++ b/clang/lib/Driver/ToolChains/Flang.cpp
@@ -329,6 +329,13 @@ void Flang::ConstructJob(Compilation &C, const JobAction &JA,
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
index f4b41b90c3b12..e87df93907ef2 100644
--- a/flang/docs/FlangDriver.md
+++ b/flang/docs/FlangDriver.md
@@ -581,6 +581,10 @@ floating point and so always acts as though these flags were specified.
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
index 9bccb7e37198a..4fb1eb8ef902c 100644
--- a/flang/lib/Frontend/CompilerInvocation.cpp
+++ b/flang/lib/Frontend/CompilerInvocation.cpp
@@ -610,14 +610,17 @@ static bool parseDiagArgs(CompilerInvocation &res, llvm::opt::ArgList &args,
// TODO: Currently throws a Diagnostic for anything other than -W<error>,
// this has to change when other -W<opt>'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
index 0000000000000..84025523cf59f
--- /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
index 0000000000000..35fd0df5d5a76
--- /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
index 0000000000000..5ad18b965aebf
--- /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
More information about the flang-commits
mailing list