-
Notifications
You must be signed in to change notification settings - Fork 15k
[flang][Driver] Accept (and ignore) some gfortran-specific options #165579
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
|
@llvm/pr-subscribers-clang-driver @llvm/pr-subscribers-clang Author: Tarun Prabhu (tarunprabhu) ChangesEnable the clang_ignored_gcc_optimization_f_group in flang. These options are accepted by clang, but ignored after emitting a warning message. flang's behavior now mirrors both clang and gfortran. Fixes #158436 Full diff: https://github.com/llvm/llvm-project/pull/165579.diff 3 Files Affected:
diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td
index 8784c9d7d206d..70c862371f5b0 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -316,7 +316,8 @@ def mno_mpx : Flag<["-"], "mno-mpx">, Group<clang_ignored_legacy_options_Group>;
// Group that ignores all gcc optimizations that won't be implemented
def clang_ignored_gcc_optimization_f_Group : OptionGroup<
- "<clang_ignored_gcc_optimization_f_Group>">, Group<f_Group>, Flags<[Ignored]>;
+ "<clang_ignored_gcc_optimization_f_Group>">,
+ Group<f_Group>, Flags<[Ignored]>, Visibility<[ClangOption, FlangOption]>;
class DiagnosticOpts<string base>
: KeyPathAndMacro<"DiagnosticOpts->", base, "DIAG_"> {}
diff --git a/clang/lib/Driver/ToolChains/Flang.cpp b/clang/lib/Driver/ToolChains/Flang.cpp
index 88bce181d40d2..b1e7643e8fd97 100644
--- a/clang/lib/Driver/ToolChains/Flang.cpp
+++ b/clang/lib/Driver/ToolChains/Flang.cpp
@@ -952,6 +952,14 @@ void Flang::ConstructJob(Compilation &C, const JobAction &JA,
if (const Arg *A = Args.getLastArg(Opt))
D.Diag(diag::warn_drv_invalid_argument_for_flang) << A->getSpelling();
+ // Warn about options that are ignored by flang. These are options that are
+ // accepted by gfortran, but have no equivalent in flang.
+ for (const Arg *A :
+ Args.filtered(options::OPT_clang_ignored_gcc_optimization_f_Group)) {
+ D.Diag(diag::warn_ignored_gcc_optimization) << A->getAsString(Args);
+ A->claim();
+ }
+
const InputInfo &Input = Inputs[0];
types::ID InputType = Input.getType();
diff --git a/flang/test/Driver/flang-f-opts.f90 b/flang/test/Driver/flang-f-opts.f90
index 9ef0abaa176f0..e29d7c1d5e671 100644
--- a/flang/test/Driver/flang-f-opts.f90
+++ b/flang/test/Driver/flang-f-opts.f90
@@ -14,19 +14,21 @@
! RUN: %flang -### -S -fprofile-use=%S %s 2>&1 | FileCheck -check-prefix=CHECK-PROFILE-USE-DIR %s
! CHECK-PROFILE-USE-DIR: "-fprofile-use={{.*}}"
+! ------------------------------------------------------------------------------
! RUN: %flang -### -fbuiltin %s 2>&1 \
! RUN: | FileCheck %s -check-prefix=WARN-BUILTIN
! WARN-BUILTIN: warning: '-fbuiltin' is not valid for Fortran
-
+!
! RUN: %flang -### -fno-builtin %s 2>&1 \
! RUN: | FileCheck %s -check-prefix=WARN-NO-BUILTIN
! WARN-NO-BUILTIN: warning: '-fno-builtin' is not valid for Fortran
-
+!
! RUN: %flang -### -fbuiltin -fno-builtin %s 2>&1 \
! RUN: | FileCheck %s -check-prefix=WARN-BUILTIN-MULTIPLE
! WARN-BUILTIN-MULTIPLE: warning: '-fbuiltin' is not valid for Fortran
! WARN-BUILTIN-MULTIPLE: warning: '-fno-builtin' is not valid for Fortran
-
+!
+!-------------------------------------------------------------------------------
! When emitting an error with a suggestion, ensure that the diagnostic message
! uses '-Xflang' instead of '-Xclang'. This is typically emitted when an option
! that is available for `flang -fc1` is passed to `flang`. We use -complex-range
@@ -43,3 +45,120 @@
! RUN: | FileCheck %s -check-prefix UNKNOWN-NO-SUGGEST
!
! UNKNOWN-NO-SUGGEST: error: unknown argument: '-not-an-option'{{$}}
+!
+!-------------------------------------------------------------------------------
+! The options in the command below are gfortran-specific optimization flags that
+! are accepted by flang's driver but ignored. Check that the correct warning
+! message is displayed when these are used.
+!
+! RUN: %flang -### %s \
+! RUN: -finline-limit=1000 \
+! RUN: -finline-limit \
+! RUN: -fexpensive-optimizations \
+! RUN: -fno-expensive-optimizations \
+! RUN: -fno-defer-pop \
+! RUN: -fkeep-inline-functions \
+! RUN: -fno-keep-inline-functions \
+! RUN: -freorder-blocks \
+! RUN: -ffloat-store \
+! RUN: -fgcse \
+! RUN: -fivopts \
+! RUN: -fprefetch-loop-arrays \
+! RUN: -fprofile-correction \
+! RUN: -fprofile-values \
+! RUN: -fschedule-insns \
+! RUN: -fsignaling-nans \
+! RUN: -fstrength-reduce \
+! RUN: -ftracer \
+! RUN: -funroll-all-loops \
+! RUN: -funswitch-loops \
+! RUN: -falign-labels \
+! RUN: -falign-labels=100 \
+! RUN: -falign-jumps \
+! RUN: -falign-jumps=100 \
+! RUN: -fbranch-count-reg \
+! RUN: -fcaller-saves \
+! RUN: -fno-default-inline \
+! RUN: -fgcse-after-reload \
+! RUN: -fgcse-las \
+! RUN: -fgcse-sm \
+! RUN: -fipa-cp \
+! RUN: -finline-functions-called-once \
+! RUN: -fmodulo-sched \
+! RUN: -fmodulo-sched-allow-regmoves \
+! RUN: -fpeel-loops \
+! RUN: -frename-registers \
+! RUN: -fschedule-insns2 \
+! RUN: -fsingle-precision-constant \
+! RUN: -funsafe-loop-optimizations \
+! RUN: -fuse-linker-plugin \
+! RUN: -fvect-cost-model \
+! RUN: -fvariable-expansion-in-unroller \
+! RUN: -fweb \
+! RUN: -fwhole-program \
+! RUN: -fcaller-saves \
+! RUN: -freorder-blocks \
+! RUN: -ffat-lto-objects \
+! RUN: -fmerge-constants \
+! RUN: -finline-small-functions \
+! RUN: -ftree-dce \
+! RUN: -ftree-ter \
+! RUN: -ftree-vrp \
+! RUN: -fno-devirtualize \
+! RUN: -fno-devirtualize-speculatively 2>&1 \
+! RUN: | FileCheck --check-prefix=CHECK-WARNING %s
+! CHECK-WARNING-DAG: optimization flag '-finline-limit=1000' is not supported
+! CHECK-WARNING-DAG: optimization flag '-finline-limit' is not supported
+! CHECK-WARNING-DAG: optimization flag '-fexpensive-optimizations' is not supported
+! CHECK-WARNING-DAG: optimization flag '-fno-expensive-optimizations' is not supported
+! CHECK-WARNING-DAG: optimization flag '-fno-defer-pop' is not supported
+! CHECK-WARNING-DAG: optimization flag '-fkeep-inline-functions' is not supported
+! CHECK-WARNING-DAG: optimization flag '-fno-keep-inline-functions' is not supported
+! CHECK-WARNING-DAG: optimization flag '-freorder-blocks' is not supported
+! CHECK-WARNING-DAG: optimization flag '-ffloat-store' is not supported
+! CHECK-WARNING-DAG: optimization flag '-fgcse' is not supported
+! CHECK-WARNING-DAG: optimization flag '-fivopts' is not supported
+! CHECK-WARNING-DAG: optimization flag '-fprefetch-loop-arrays' is not supported
+! CHECK-WARNING-DAG: optimization flag '-fprofile-correction' is not supported
+! CHECK-WARNING-DAG: optimization flag '-fprofile-values' is not supported
+! CHECK-WARNING-DAG: optimization flag '-fschedule-insns' is not supported
+! CHECK-WARNING-DAG: optimization flag '-fsignaling-nans' is not supported
+! CHECK-WARNING-DAG: optimization flag '-fstrength-reduce' is not supported
+! CHECK-WARNING-DAG: optimization flag '-ftracer' is not supported
+! CHECK-WARNING-DAG: optimization flag '-funroll-all-loops' is not supported
+! CHECK-WARNING-DAG: optimization flag '-funswitch-loops' is not supported
+! CHECK-WARNING-DAG: optimization flag '-falign-labels' is not supported
+! CHECK-WARNING-DAG: optimization flag '-falign-labels=100' is not supported
+! CHECK-WARNING-DAG: optimization flag '-falign-jumps' is not supported
+! CHECK-WARNING-DAG: optimization flag '-falign-jumps=100' is not supported
+! CHECK-WARNING-DAG: optimization flag '-fbranch-count-reg' is not supported
+! CHECK-WARNING-DAG: optimization flag '-fcaller-saves' is not supported
+! CHECK-WARNING-DAG: optimization flag '-fno-default-inline' is not supported
+! CHECK-WARNING-DAG: optimization flag '-fgcse-after-reload' is not supported
+! CHECK-WARNING-DAG: optimization flag '-fgcse-las' is not supported
+! CHECK-WARNING-DAG: optimization flag '-fgcse-sm' is not supported
+! CHECK-WARNING-DAG: optimization flag '-fipa-cp' is not supported
+! CHECK-WARNING-DAG: optimization flag '-finline-functions-called-once' is not supported
+! CHECK-WARNING-DAG: optimization flag '-fmodulo-sched' is not supported
+! CHECK-WARNING-DAG: optimization flag '-fmodulo-sched-allow-regmoves' is not supported
+! CHECK-WARNING-DAG: optimization flag '-fpeel-loops' is not supported
+! CHECK-WARNING-DAG: optimization flag '-frename-registers' is not supported
+! CHECK-WARNING-DAG: optimization flag '-fschedule-insns2' is not supported
+! CHECK-WARNING-DAG: optimization flag '-fsingle-precision-constant' is not supported
+! CHECK-WARNING-DAG: optimization flag '-funsafe-loop-optimizations' is not supported
+! CHECK-WARNING-DAG: optimization flag '-fuse-linker-plugin' is not supported
+! CHECK-WARNING-DAG: optimization flag '-fvect-cost-model' is not supported
+! CHECK-WARNING-DAG: optimization flag '-fvariable-expansion-in-unroller' is not supported
+! CHECK-WARNING-DAG: optimization flag '-fweb' is not supported
+! CHECK-WARNING-DAG: optimization flag '-fwhole-program' is not supported
+! CHECK-WARNING-DAG: optimization flag '-fcaller-saves' is not supported
+! CHECK-WARNING-DAG: optimization flag '-freorder-blocks' is not supported
+! CHECK-WARNING-DAG: optimization flag '-fmerge-constants' is not supported
+! CHECK-WARNING-DAG: optimization flag '-finline-small-functions' is not supported
+! CHECK-WARNING-DAG: optimization flag '-ftree-dce' is not supported
+! CHECK-WARNING-DAG: optimization flag '-ftree-ter' is not supported
+! CHECK-WARNING-DAG: optimization flag '-ftree-vrp' is not supported
+! CHECK-WARNING-DAG: optimization flag '-fno-devirtualize' is not supported
+! CHECK-WARNING-DAG: optimization flag '-fno-devirtualize-speculatively' is not supported
+!
+! ------------------------------------------------------------------------------
|
|
@llvm/pr-subscribers-flang-driver Author: Tarun Prabhu (tarunprabhu) ChangesEnable the clang_ignored_gcc_optimization_f_group in flang. These options are accepted by clang, but ignored after emitting a warning message. flang's behavior now mirrors both clang and gfortran. Fixes #158436 Full diff: https://github.com/llvm/llvm-project/pull/165579.diff 3 Files Affected:
diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td
index 8784c9d7d206d..70c862371f5b0 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -316,7 +316,8 @@ def mno_mpx : Flag<["-"], "mno-mpx">, Group<clang_ignored_legacy_options_Group>;
// Group that ignores all gcc optimizations that won't be implemented
def clang_ignored_gcc_optimization_f_Group : OptionGroup<
- "<clang_ignored_gcc_optimization_f_Group>">, Group<f_Group>, Flags<[Ignored]>;
+ "<clang_ignored_gcc_optimization_f_Group>">,
+ Group<f_Group>, Flags<[Ignored]>, Visibility<[ClangOption, FlangOption]>;
class DiagnosticOpts<string base>
: KeyPathAndMacro<"DiagnosticOpts->", base, "DIAG_"> {}
diff --git a/clang/lib/Driver/ToolChains/Flang.cpp b/clang/lib/Driver/ToolChains/Flang.cpp
index 88bce181d40d2..b1e7643e8fd97 100644
--- a/clang/lib/Driver/ToolChains/Flang.cpp
+++ b/clang/lib/Driver/ToolChains/Flang.cpp
@@ -952,6 +952,14 @@ void Flang::ConstructJob(Compilation &C, const JobAction &JA,
if (const Arg *A = Args.getLastArg(Opt))
D.Diag(diag::warn_drv_invalid_argument_for_flang) << A->getSpelling();
+ // Warn about options that are ignored by flang. These are options that are
+ // accepted by gfortran, but have no equivalent in flang.
+ for (const Arg *A :
+ Args.filtered(options::OPT_clang_ignored_gcc_optimization_f_Group)) {
+ D.Diag(diag::warn_ignored_gcc_optimization) << A->getAsString(Args);
+ A->claim();
+ }
+
const InputInfo &Input = Inputs[0];
types::ID InputType = Input.getType();
diff --git a/flang/test/Driver/flang-f-opts.f90 b/flang/test/Driver/flang-f-opts.f90
index 9ef0abaa176f0..e29d7c1d5e671 100644
--- a/flang/test/Driver/flang-f-opts.f90
+++ b/flang/test/Driver/flang-f-opts.f90
@@ -14,19 +14,21 @@
! RUN: %flang -### -S -fprofile-use=%S %s 2>&1 | FileCheck -check-prefix=CHECK-PROFILE-USE-DIR %s
! CHECK-PROFILE-USE-DIR: "-fprofile-use={{.*}}"
+! ------------------------------------------------------------------------------
! RUN: %flang -### -fbuiltin %s 2>&1 \
! RUN: | FileCheck %s -check-prefix=WARN-BUILTIN
! WARN-BUILTIN: warning: '-fbuiltin' is not valid for Fortran
-
+!
! RUN: %flang -### -fno-builtin %s 2>&1 \
! RUN: | FileCheck %s -check-prefix=WARN-NO-BUILTIN
! WARN-NO-BUILTIN: warning: '-fno-builtin' is not valid for Fortran
-
+!
! RUN: %flang -### -fbuiltin -fno-builtin %s 2>&1 \
! RUN: | FileCheck %s -check-prefix=WARN-BUILTIN-MULTIPLE
! WARN-BUILTIN-MULTIPLE: warning: '-fbuiltin' is not valid for Fortran
! WARN-BUILTIN-MULTIPLE: warning: '-fno-builtin' is not valid for Fortran
-
+!
+!-------------------------------------------------------------------------------
! When emitting an error with a suggestion, ensure that the diagnostic message
! uses '-Xflang' instead of '-Xclang'. This is typically emitted when an option
! that is available for `flang -fc1` is passed to `flang`. We use -complex-range
@@ -43,3 +45,120 @@
! RUN: | FileCheck %s -check-prefix UNKNOWN-NO-SUGGEST
!
! UNKNOWN-NO-SUGGEST: error: unknown argument: '-not-an-option'{{$}}
+!
+!-------------------------------------------------------------------------------
+! The options in the command below are gfortran-specific optimization flags that
+! are accepted by flang's driver but ignored. Check that the correct warning
+! message is displayed when these are used.
+!
+! RUN: %flang -### %s \
+! RUN: -finline-limit=1000 \
+! RUN: -finline-limit \
+! RUN: -fexpensive-optimizations \
+! RUN: -fno-expensive-optimizations \
+! RUN: -fno-defer-pop \
+! RUN: -fkeep-inline-functions \
+! RUN: -fno-keep-inline-functions \
+! RUN: -freorder-blocks \
+! RUN: -ffloat-store \
+! RUN: -fgcse \
+! RUN: -fivopts \
+! RUN: -fprefetch-loop-arrays \
+! RUN: -fprofile-correction \
+! RUN: -fprofile-values \
+! RUN: -fschedule-insns \
+! RUN: -fsignaling-nans \
+! RUN: -fstrength-reduce \
+! RUN: -ftracer \
+! RUN: -funroll-all-loops \
+! RUN: -funswitch-loops \
+! RUN: -falign-labels \
+! RUN: -falign-labels=100 \
+! RUN: -falign-jumps \
+! RUN: -falign-jumps=100 \
+! RUN: -fbranch-count-reg \
+! RUN: -fcaller-saves \
+! RUN: -fno-default-inline \
+! RUN: -fgcse-after-reload \
+! RUN: -fgcse-las \
+! RUN: -fgcse-sm \
+! RUN: -fipa-cp \
+! RUN: -finline-functions-called-once \
+! RUN: -fmodulo-sched \
+! RUN: -fmodulo-sched-allow-regmoves \
+! RUN: -fpeel-loops \
+! RUN: -frename-registers \
+! RUN: -fschedule-insns2 \
+! RUN: -fsingle-precision-constant \
+! RUN: -funsafe-loop-optimizations \
+! RUN: -fuse-linker-plugin \
+! RUN: -fvect-cost-model \
+! RUN: -fvariable-expansion-in-unroller \
+! RUN: -fweb \
+! RUN: -fwhole-program \
+! RUN: -fcaller-saves \
+! RUN: -freorder-blocks \
+! RUN: -ffat-lto-objects \
+! RUN: -fmerge-constants \
+! RUN: -finline-small-functions \
+! RUN: -ftree-dce \
+! RUN: -ftree-ter \
+! RUN: -ftree-vrp \
+! RUN: -fno-devirtualize \
+! RUN: -fno-devirtualize-speculatively 2>&1 \
+! RUN: | FileCheck --check-prefix=CHECK-WARNING %s
+! CHECK-WARNING-DAG: optimization flag '-finline-limit=1000' is not supported
+! CHECK-WARNING-DAG: optimization flag '-finline-limit' is not supported
+! CHECK-WARNING-DAG: optimization flag '-fexpensive-optimizations' is not supported
+! CHECK-WARNING-DAG: optimization flag '-fno-expensive-optimizations' is not supported
+! CHECK-WARNING-DAG: optimization flag '-fno-defer-pop' is not supported
+! CHECK-WARNING-DAG: optimization flag '-fkeep-inline-functions' is not supported
+! CHECK-WARNING-DAG: optimization flag '-fno-keep-inline-functions' is not supported
+! CHECK-WARNING-DAG: optimization flag '-freorder-blocks' is not supported
+! CHECK-WARNING-DAG: optimization flag '-ffloat-store' is not supported
+! CHECK-WARNING-DAG: optimization flag '-fgcse' is not supported
+! CHECK-WARNING-DAG: optimization flag '-fivopts' is not supported
+! CHECK-WARNING-DAG: optimization flag '-fprefetch-loop-arrays' is not supported
+! CHECK-WARNING-DAG: optimization flag '-fprofile-correction' is not supported
+! CHECK-WARNING-DAG: optimization flag '-fprofile-values' is not supported
+! CHECK-WARNING-DAG: optimization flag '-fschedule-insns' is not supported
+! CHECK-WARNING-DAG: optimization flag '-fsignaling-nans' is not supported
+! CHECK-WARNING-DAG: optimization flag '-fstrength-reduce' is not supported
+! CHECK-WARNING-DAG: optimization flag '-ftracer' is not supported
+! CHECK-WARNING-DAG: optimization flag '-funroll-all-loops' is not supported
+! CHECK-WARNING-DAG: optimization flag '-funswitch-loops' is not supported
+! CHECK-WARNING-DAG: optimization flag '-falign-labels' is not supported
+! CHECK-WARNING-DAG: optimization flag '-falign-labels=100' is not supported
+! CHECK-WARNING-DAG: optimization flag '-falign-jumps' is not supported
+! CHECK-WARNING-DAG: optimization flag '-falign-jumps=100' is not supported
+! CHECK-WARNING-DAG: optimization flag '-fbranch-count-reg' is not supported
+! CHECK-WARNING-DAG: optimization flag '-fcaller-saves' is not supported
+! CHECK-WARNING-DAG: optimization flag '-fno-default-inline' is not supported
+! CHECK-WARNING-DAG: optimization flag '-fgcse-after-reload' is not supported
+! CHECK-WARNING-DAG: optimization flag '-fgcse-las' is not supported
+! CHECK-WARNING-DAG: optimization flag '-fgcse-sm' is not supported
+! CHECK-WARNING-DAG: optimization flag '-fipa-cp' is not supported
+! CHECK-WARNING-DAG: optimization flag '-finline-functions-called-once' is not supported
+! CHECK-WARNING-DAG: optimization flag '-fmodulo-sched' is not supported
+! CHECK-WARNING-DAG: optimization flag '-fmodulo-sched-allow-regmoves' is not supported
+! CHECK-WARNING-DAG: optimization flag '-fpeel-loops' is not supported
+! CHECK-WARNING-DAG: optimization flag '-frename-registers' is not supported
+! CHECK-WARNING-DAG: optimization flag '-fschedule-insns2' is not supported
+! CHECK-WARNING-DAG: optimization flag '-fsingle-precision-constant' is not supported
+! CHECK-WARNING-DAG: optimization flag '-funsafe-loop-optimizations' is not supported
+! CHECK-WARNING-DAG: optimization flag '-fuse-linker-plugin' is not supported
+! CHECK-WARNING-DAG: optimization flag '-fvect-cost-model' is not supported
+! CHECK-WARNING-DAG: optimization flag '-fvariable-expansion-in-unroller' is not supported
+! CHECK-WARNING-DAG: optimization flag '-fweb' is not supported
+! CHECK-WARNING-DAG: optimization flag '-fwhole-program' is not supported
+! CHECK-WARNING-DAG: optimization flag '-fcaller-saves' is not supported
+! CHECK-WARNING-DAG: optimization flag '-freorder-blocks' is not supported
+! CHECK-WARNING-DAG: optimization flag '-fmerge-constants' is not supported
+! CHECK-WARNING-DAG: optimization flag '-finline-small-functions' is not supported
+! CHECK-WARNING-DAG: optimization flag '-ftree-dce' is not supported
+! CHECK-WARNING-DAG: optimization flag '-ftree-ter' is not supported
+! CHECK-WARNING-DAG: optimization flag '-ftree-vrp' is not supported
+! CHECK-WARNING-DAG: optimization flag '-fno-devirtualize' is not supported
+! CHECK-WARNING-DAG: optimization flag '-fno-devirtualize-speculatively' is not supported
+!
+! ------------------------------------------------------------------------------
|
Enable the clang_ignored_gcc_optimization_f_group in flang. These options are accepted by clang, but ignored after emitting a warning message. flang's behavior now mirrors both clang and gfortran. Fixes llvm#158436
d589406 to
95baa7d
Compare
Enable the clang_ignored_gcc_optimization_f_group in flang. These options are accepted by clang, but ignored after emitting a warning message. flang's behavior now mirrors both clang and gfortran.
Fixes #158436