Skip to content

Commit d589406

Browse files
Tarun Prabhutarunprabhu
authored andcommitted
[flang][Driver] Accept (and ignore) some gfortran-specific options
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
1 parent 9ab9d33 commit d589406

File tree

3 files changed

+132
-4
lines changed

3 files changed

+132
-4
lines changed

clang/include/clang/Driver/Options.td

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,8 @@ def mno_mpx : Flag<["-"], "mno-mpx">, Group<clang_ignored_legacy_options_Group>;
316316

317317
// Group that ignores all gcc optimizations that won't be implemented
318318
def clang_ignored_gcc_optimization_f_Group : OptionGroup<
319-
"<clang_ignored_gcc_optimization_f_Group>">, Group<f_Group>, Flags<[Ignored]>;
319+
"<clang_ignored_gcc_optimization_f_Group>">,
320+
Group<f_Group>, Flags<[Ignored]>, Visibility<[ClangOption, FlangOption]>;
320321

321322
class DiagnosticOpts<string base>
322323
: KeyPathAndMacro<"DiagnosticOpts->", base, "DIAG_"> {}

clang/lib/Driver/ToolChains/Flang.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -952,6 +952,14 @@ void Flang::ConstructJob(Compilation &C, const JobAction &JA,
952952
if (const Arg *A = Args.getLastArg(Opt))
953953
D.Diag(diag::warn_drv_invalid_argument_for_flang) << A->getSpelling();
954954

955+
// Warn about options that are ignored by flang. These are options that are
956+
// accepted by gfortran, but have no equivalent in flang.
957+
for (const Arg *A :
958+
Args.filtered(options::OPT_clang_ignored_gcc_optimization_f_Group)) {
959+
D.Diag(diag::warn_ignored_gcc_optimization) << A->getAsString(Args);
960+
A->claim();
961+
}
962+
955963
const InputInfo &Input = Inputs[0];
956964
types::ID InputType = Input.getType();
957965

flang/test/Driver/flang-f-opts.f90

Lines changed: 122 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,19 +14,21 @@
1414
! RUN: %flang -### -S -fprofile-use=%S %s 2>&1 | FileCheck -check-prefix=CHECK-PROFILE-USE-DIR %s
1515
! CHECK-PROFILE-USE-DIR: "-fprofile-use={{.*}}"
1616

17+
! ------------------------------------------------------------------------------
1718
! RUN: %flang -### -fbuiltin %s 2>&1 \
1819
! RUN: | FileCheck %s -check-prefix=WARN-BUILTIN
1920
! WARN-BUILTIN: warning: '-fbuiltin' is not valid for Fortran
20-
21+
!
2122
! RUN: %flang -### -fno-builtin %s 2>&1 \
2223
! RUN: | FileCheck %s -check-prefix=WARN-NO-BUILTIN
2324
! WARN-NO-BUILTIN: warning: '-fno-builtin' is not valid for Fortran
24-
25+
!
2526
! RUN: %flang -### -fbuiltin -fno-builtin %s 2>&1 \
2627
! RUN: | FileCheck %s -check-prefix=WARN-BUILTIN-MULTIPLE
2728
! WARN-BUILTIN-MULTIPLE: warning: '-fbuiltin' is not valid for Fortran
2829
! WARN-BUILTIN-MULTIPLE: warning: '-fno-builtin' is not valid for Fortran
29-
30+
!
31+
!-------------------------------------------------------------------------------
3032
! When emitting an error with a suggestion, ensure that the diagnostic message
3133
! uses '-Xflang' instead of '-Xclang'. This is typically emitted when an option
3234
! that is available for `flang -fc1` is passed to `flang`. We use -complex-range
@@ -43,3 +45,120 @@
4345
! RUN: | FileCheck %s -check-prefix UNKNOWN-NO-SUGGEST
4446
!
4547
! UNKNOWN-NO-SUGGEST: error: unknown argument: '-not-an-option'{{$}}
48+
!
49+
!-------------------------------------------------------------------------------
50+
! The options in the command below are gfortran-specific optimization flags that
51+
! are accepted by flang's driver but ignored. Check that the correct warning
52+
! message is displayed when these are used.
53+
!
54+
! RUN: %flang -### %s \
55+
! RUN: -finline-limit=1000 \
56+
! RUN: -finline-limit \
57+
! RUN: -fexpensive-optimizations \
58+
! RUN: -fno-expensive-optimizations \
59+
! RUN: -fno-defer-pop \
60+
! RUN: -fkeep-inline-functions \
61+
! RUN: -fno-keep-inline-functions \
62+
! RUN: -freorder-blocks \
63+
! RUN: -ffloat-store \
64+
! RUN: -fgcse \
65+
! RUN: -fivopts \
66+
! RUN: -fprefetch-loop-arrays \
67+
! RUN: -fprofile-correction \
68+
! RUN: -fprofile-values \
69+
! RUN: -fschedule-insns \
70+
! RUN: -fsignaling-nans \
71+
! RUN: -fstrength-reduce \
72+
! RUN: -ftracer \
73+
! RUN: -funroll-all-loops \
74+
! RUN: -funswitch-loops \
75+
! RUN: -falign-labels \
76+
! RUN: -falign-labels=100 \
77+
! RUN: -falign-jumps \
78+
! RUN: -falign-jumps=100 \
79+
! RUN: -fbranch-count-reg \
80+
! RUN: -fcaller-saves \
81+
! RUN: -fno-default-inline \
82+
! RUN: -fgcse-after-reload \
83+
! RUN: -fgcse-las \
84+
! RUN: -fgcse-sm \
85+
! RUN: -fipa-cp \
86+
! RUN: -finline-functions-called-once \
87+
! RUN: -fmodulo-sched \
88+
! RUN: -fmodulo-sched-allow-regmoves \
89+
! RUN: -fpeel-loops \
90+
! RUN: -frename-registers \
91+
! RUN: -fschedule-insns2 \
92+
! RUN: -fsingle-precision-constant \
93+
! RUN: -funsafe-loop-optimizations \
94+
! RUN: -fuse-linker-plugin \
95+
! RUN: -fvect-cost-model \
96+
! RUN: -fvariable-expansion-in-unroller \
97+
! RUN: -fweb \
98+
! RUN: -fwhole-program \
99+
! RUN: -fcaller-saves \
100+
! RUN: -freorder-blocks \
101+
! RUN: -ffat-lto-objects \
102+
! RUN: -fmerge-constants \
103+
! RUN: -finline-small-functions \
104+
! RUN: -ftree-dce \
105+
! RUN: -ftree-ter \
106+
! RUN: -ftree-vrp \
107+
! RUN: -fno-devirtualize \
108+
! RUN: -fno-devirtualize-speculatively 2>&1 \
109+
! RUN: | FileCheck --check-prefix=CHECK-WARNING %s
110+
! CHECK-WARNING-DAG: optimization flag '-finline-limit=1000' is not supported
111+
! CHECK-WARNING-DAG: optimization flag '-finline-limit' is not supported
112+
! CHECK-WARNING-DAG: optimization flag '-fexpensive-optimizations' is not supported
113+
! CHECK-WARNING-DAG: optimization flag '-fno-expensive-optimizations' is not supported
114+
! CHECK-WARNING-DAG: optimization flag '-fno-defer-pop' is not supported
115+
! CHECK-WARNING-DAG: optimization flag '-fkeep-inline-functions' is not supported
116+
! CHECK-WARNING-DAG: optimization flag '-fno-keep-inline-functions' is not supported
117+
! CHECK-WARNING-DAG: optimization flag '-freorder-blocks' is not supported
118+
! CHECK-WARNING-DAG: optimization flag '-ffloat-store' is not supported
119+
! CHECK-WARNING-DAG: optimization flag '-fgcse' is not supported
120+
! CHECK-WARNING-DAG: optimization flag '-fivopts' is not supported
121+
! CHECK-WARNING-DAG: optimization flag '-fprefetch-loop-arrays' is not supported
122+
! CHECK-WARNING-DAG: optimization flag '-fprofile-correction' is not supported
123+
! CHECK-WARNING-DAG: optimization flag '-fprofile-values' is not supported
124+
! CHECK-WARNING-DAG: optimization flag '-fschedule-insns' is not supported
125+
! CHECK-WARNING-DAG: optimization flag '-fsignaling-nans' is not supported
126+
! CHECK-WARNING-DAG: optimization flag '-fstrength-reduce' is not supported
127+
! CHECK-WARNING-DAG: optimization flag '-ftracer' is not supported
128+
! CHECK-WARNING-DAG: optimization flag '-funroll-all-loops' is not supported
129+
! CHECK-WARNING-DAG: optimization flag '-funswitch-loops' is not supported
130+
! CHECK-WARNING-DAG: optimization flag '-falign-labels' is not supported
131+
! CHECK-WARNING-DAG: optimization flag '-falign-labels=100' is not supported
132+
! CHECK-WARNING-DAG: optimization flag '-falign-jumps' is not supported
133+
! CHECK-WARNING-DAG: optimization flag '-falign-jumps=100' is not supported
134+
! CHECK-WARNING-DAG: optimization flag '-fbranch-count-reg' is not supported
135+
! CHECK-WARNING-DAG: optimization flag '-fcaller-saves' is not supported
136+
! CHECK-WARNING-DAG: optimization flag '-fno-default-inline' is not supported
137+
! CHECK-WARNING-DAG: optimization flag '-fgcse-after-reload' is not supported
138+
! CHECK-WARNING-DAG: optimization flag '-fgcse-las' is not supported
139+
! CHECK-WARNING-DAG: optimization flag '-fgcse-sm' is not supported
140+
! CHECK-WARNING-DAG: optimization flag '-fipa-cp' is not supported
141+
! CHECK-WARNING-DAG: optimization flag '-finline-functions-called-once' is not supported
142+
! CHECK-WARNING-DAG: optimization flag '-fmodulo-sched' is not supported
143+
! CHECK-WARNING-DAG: optimization flag '-fmodulo-sched-allow-regmoves' is not supported
144+
! CHECK-WARNING-DAG: optimization flag '-fpeel-loops' is not supported
145+
! CHECK-WARNING-DAG: optimization flag '-frename-registers' is not supported
146+
! CHECK-WARNING-DAG: optimization flag '-fschedule-insns2' is not supported
147+
! CHECK-WARNING-DAG: optimization flag '-fsingle-precision-constant' is not supported
148+
! CHECK-WARNING-DAG: optimization flag '-funsafe-loop-optimizations' is not supported
149+
! CHECK-WARNING-DAG: optimization flag '-fuse-linker-plugin' is not supported
150+
! CHECK-WARNING-DAG: optimization flag '-fvect-cost-model' is not supported
151+
! CHECK-WARNING-DAG: optimization flag '-fvariable-expansion-in-unroller' is not supported
152+
! CHECK-WARNING-DAG: optimization flag '-fweb' is not supported
153+
! CHECK-WARNING-DAG: optimization flag '-fwhole-program' is not supported
154+
! CHECK-WARNING-DAG: optimization flag '-fcaller-saves' is not supported
155+
! CHECK-WARNING-DAG: optimization flag '-freorder-blocks' is not supported
156+
! CHECK-WARNING-DAG: optimization flag '-fmerge-constants' is not supported
157+
! CHECK-WARNING-DAG: optimization flag '-finline-small-functions' is not supported
158+
! CHECK-WARNING-DAG: optimization flag '-ftree-dce' is not supported
159+
! CHECK-WARNING-DAG: optimization flag '-ftree-ter' is not supported
160+
! CHECK-WARNING-DAG: optimization flag '-ftree-vrp' is not supported
161+
! CHECK-WARNING-DAG: optimization flag '-fno-devirtualize' is not supported
162+
! CHECK-WARNING-DAG: optimization flag '-fno-devirtualize-speculatively' is not supported
163+
!
164+
! ------------------------------------------------------------------------------

0 commit comments

Comments
 (0)