Skip to content

Commit 263377a

Browse files
authored
[flang][Driver] Warn on -fbuiltin and -fno-builtin
The options -fbuiltin and -fno-builtin are not valid for Fortran. However, they are accepted by gfortran which emits a warning message but continues to compile the code. Both -fbuiltin and -fno-builtin have been enabled for flang. Specifying either will result in a warning message being shown but no other effects. Compilation will proceed normally after these warnings are shown. This brings flang's behavior in line with gfortran for these options. Fixes #164766
1 parent c1f6528 commit 263377a

File tree

4 files changed

+25
-2
lines changed

4 files changed

+25
-2
lines changed

clang/include/clang/Basic/DiagnosticDriverKinds.td

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,9 @@ def warn_drv_unsupported_option_for_offload_arch_req_feature : Warning<
133133
def warn_drv_unsupported_option_for_target : Warning<
134134
"ignoring '%0' option as it is not currently supported for target '%1'">,
135135
InGroup<OptionIgnored>;
136+
def warn_drv_invalid_argument_for_flang : Warning<
137+
"'%0' is not valid for Fortran">,
138+
InGroup<OptionIgnored>;
136139
def warn_drv_unsupported_option_for_flang : Warning<
137140
"the argument '%0' is not supported for option '%1'. Mapping to '%1%2'">,
138141
InGroup<OptionIgnored>;

clang/include/clang/Driver/Options.td

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1955,7 +1955,7 @@ defm borland_extensions : BoolFOption<"borland-extensions",
19551955
"Accept non-standard constructs supported by the Borland compiler">,
19561956
NegFlag<SetFalse>>;
19571957
def fbuiltin : Flag<["-"], "fbuiltin">, Group<f_Group>,
1958-
Visibility<[ClangOption, CLOption, DXCOption]>;
1958+
Visibility<[ClangOption, CLOption, DXCOption, FlangOption, FC1Option]>;
19591959
def fbuiltin_module_map : Flag <["-"], "fbuiltin-module-map">, Group<f_Group>,
19601960
Flags<[]>, HelpText<"Load the clang builtins module map file.">;
19611961
defm caret_diagnostics : BoolFOption<"caret-diagnostics",
@@ -3563,7 +3563,7 @@ def fno_assume_sane_operator_new : Flag<["-"], "fno-assume-sane-operator-new">,
35633563
Visibility<[ClangOption, CC1Option]>,
35643564
MarshallingInfoNegativeFlag<CodeGenOpts<"AssumeSaneOperatorNew">>;
35653565
def fno_builtin : Flag<["-"], "fno-builtin">, Group<f_Group>,
3566-
Visibility<[ClangOption, CC1Option, CLOption, DXCOption]>,
3566+
Visibility<[ClangOption, CC1Option, CLOption, DXCOption, FlangOption, FC1Option]>,
35673567
HelpText<"Disable implicit builtin knowledge of functions">;
35683568
def fno_builtin_ : Joined<["-"], "fno-builtin-">, Group<f_Group>,
35693569
Visibility<[ClangOption, CC1Option, CLOption, DXCOption]>,

clang/lib/Driver/ToolChains/Flang.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -945,6 +945,13 @@ void Flang::ConstructJob(Compilation &C, const JobAction &JA,
945945
assert(false && "Unexpected action class for Flang tool.");
946946
}
947947

948+
// We support some options that are invalid for Fortran and have no effect.
949+
// These are solely for compatibility with other compilers. Emit a warning if
950+
// any such options are provided, then proceed normally.
951+
for (options::ID Opt : {options::OPT_fbuiltin, options::OPT_fno_builtin})
952+
if (const Arg *A = Args.getLastArg(Opt))
953+
D.Diag(diag::warn_drv_invalid_argument_for_flang) << A->getSpelling();
954+
948955
const InputInfo &Input = Inputs[0];
949956
types::ID InputType = Input.getType();
950957

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,16 @@
1313
! CHECK-PROFILE-GENERATE-LLVM: "-fprofile-generate"
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={{.*}}"
16+
17+
! RUN: %flang -### -fbuiltin %s 2>&1 \
18+
! RUN: | FileCheck %s -check-prefix=WARN-BUILTIN
19+
! WARN-BUILTIN: warning: '-fbuiltin' is not valid for Fortran
20+
21+
! RUN: %flang -### -fno-builtin %s 2>&1 \
22+
! RUN: | FileCheck %s -check-prefix=WARN-NO-BUILTIN
23+
! WARN-NO-BUILTIN: warning: '-fno-builtin' is not valid for Fortran
24+
25+
! RUN: %flang -### -fbuiltin -fno-builtin %s 2>&1 \
26+
! RUN: | FileCheck %s -check-prefix=WARN-BUILTIN-MULTIPLE
27+
! WARN-BUILTIN-MULTIPLE: warning: '-fbuiltin' is not valid for Fortran
28+
! WARN-BUILTIN-MULTIPLE: warning: '-fno-builtin' is not valid for Fortran

0 commit comments

Comments
 (0)