Skip to content

Commit 7211bf4

Browse files
authored
[flang][driver] add negative from of -fsave-main-program (#124110)
Add the `-fno` form for consistency and to make it easy to switch the default for downstream users.
1 parent bbf3770 commit 7211bf4

File tree

5 files changed

+18
-8
lines changed

5 files changed

+18
-8
lines changed

clang/include/clang/Driver/Options.td

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6970,8 +6970,11 @@ defm unsigned : OptInFC1FFlag<"unsigned", "Enables UNSIGNED type">;
69706970
def fno_automatic : Flag<["-"], "fno-automatic">, Group<f_Group>,
69716971
HelpText<"Implies the SAVE attribute for non-automatic local objects in subprograms unless RECURSIVE">;
69726972

6973-
def fsave_main_program : Flag<["-"], "fsave-main-program">, Group<f_Group>,
6974-
HelpText<"Place all variables from the main program in static memory (otherwise scalars may be placed on the stack)">;
6973+
defm save_main_program : BoolOptionWithoutMarshalling<"f", "save-main-program",
6974+
PosFlag<SetTrue, [], [],
6975+
"Place all main program variables in static memory (otherwise scalars may be placed on the stack)">,
6976+
NegFlag<SetFalse, [], [],
6977+
"Allow placing main program variables on the stack (default)">>;
69756978

69766979
defm stack_arrays : BoolOptionWithoutMarshalling<"f", "stack-arrays",
69776980
PosFlag<SetTrue, [], [ClangOption], "Attempt to allocate array temporaries on the stack, no matter their size">,

clang/lib/Driver/ToolChains/Flang.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,8 @@ void Flang::addFortranDialectOptions(const ArgList &Args,
5858
options::OPT_fhermetic_module_files,
5959
options::OPT_frealloc_lhs,
6060
options::OPT_fno_realloc_lhs,
61-
options::OPT_fsave_main_program});
61+
options::OPT_fsave_main_program,
62+
options::OPT_fno_save_main_program});
6263
}
6364

6465
void Flang::addPreprocessingOptions(const ArgList &Args,

flang/lib/Frontend/CompilerInvocation.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -770,10 +770,11 @@ static bool parseFrontendArgs(FrontendOptions &opts, llvm::opt::ArgList &args,
770770
opts.features.Enable(Fortran::common::LanguageFeature::DefaultSave);
771771
}
772772

773-
// -fsave-main-program
774-
if (args.hasArg(clang::driver::options::OPT_fsave_main_program)) {
775-
opts.features.Enable(Fortran::common::LanguageFeature::SaveMainProgram);
776-
}
773+
// -f{no}-save-main-program
774+
opts.features.Enable(
775+
Fortran::common::LanguageFeature::SaveMainProgram,
776+
args.hasFlag(clang::driver::options::OPT_fsave_main_program,
777+
clang::driver::options::OPT_fno_save_main_program, false));
777778

778779
if (args.hasArg(
779780
clang::driver::options::OPT_falternative_parameter_statement)) {

flang/test/Driver/fsave-main-program.f90

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
! Check that the driver passes through -fsave-main-program:
22
! RUN: %flang -### -S -fsave-main-program %s -o - 2>&1 | FileCheck %s
3+
! CHECK: "-fc1"{{.*}}"-fsave-main-program"
4+
5+
! RUN: %flang -### -S -fno-save-main-program %s -o - 2>&1 | FileCheck %s --check-prefix=CHECK2
6+
! CHECK2: "-fc1"{{.*}}"-fno-save-main-program"
7+
38
! Check that the compiler accepts -fsave-main-program:
49
! RUN: %flang_fc1 -emit-hlfir -fsave-main-program %s -o -
5-
! CHECK: "-fc1"{{.*}}"-fsave-main-program"

flang/test/Lower/fsave-main-program.f90

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
! Test -fsave-main-program switch.
22
! RUN: %flang_fc1 -emit-hlfir -o - %s | FileCheck --check-prefix=CHECK-DEFAULT %s
33
! RUN: %flang_fc1 -fsave-main-program -emit-hlfir -o - %s | FileCheck --check-prefix=CHECK-SAVE %s
4+
! RUN: %flang_fc1 -fsave-main-program -fno-save-main-program -emit-hlfir -o - %s | FileCheck --check-prefix=CHECK-DEFAULT %s
45
program test
56
integer :: i
67
call foo(i)

0 commit comments

Comments
 (0)