Skip to content

[flang][driver] add negative from of -fsave-main-program #124110

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

Merged
merged 3 commits into from
Jan 27, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions clang/include/clang/Driver/Options.td
Original file line number Diff line number Diff line change
Expand Up @@ -6968,8 +6968,11 @@ defm unsigned : OptInFC1FFlag<"unsigned", "Enables UNSIGNED type">;
def fno_automatic : Flag<["-"], "fno-automatic">, Group<f_Group>,
HelpText<"Implies the SAVE attribute for non-automatic local objects in subprograms unless RECURSIVE">;

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

defm stack_arrays : BoolOptionWithoutMarshalling<"f", "stack-arrays",
PosFlag<SetTrue, [], [ClangOption], "Attempt to allocate array temporaries on the stack, no matter their size">,
Expand Down
3 changes: 2 additions & 1 deletion clang/lib/Driver/ToolChains/Flang.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ void Flang::addFortranDialectOptions(const ArgList &Args,
options::OPT_fhermetic_module_files,
options::OPT_frealloc_lhs,
options::OPT_fno_realloc_lhs,
options::OPT_fsave_main_program});
options::OPT_fsave_main_program,
options::OPT_fno_save_main_program});
}

void Flang::addPreprocessingOptions(const ArgList &Args,
Expand Down
9 changes: 5 additions & 4 deletions flang/lib/Frontend/CompilerInvocation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -770,10 +770,11 @@ static bool parseFrontendArgs(FrontendOptions &opts, llvm::opt::ArgList &args,
opts.features.Enable(Fortran::common::LanguageFeature::DefaultSave);
}

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

if (args.hasArg(
clang::driver::options::OPT_falternative_parameter_statement)) {
Expand Down
6 changes: 5 additions & 1 deletion flang/test/Driver/fsave-main-program.f90
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
! Check that the driver passes through -fsave-main-program:
! RUN: %flang -### -S -fsave-main-program %s -o - 2>&1 | FileCheck %s
! CHECK: "-fc1"{{.*}}"-fsave-main-program"

! RUN: %flang -### -S -fno-save-main-program %s -o - 2>&1 | FileCheck %s --check-prefix=CHECK2
! CHECK2: "-fc1"{{.*}}"-fno-save-main-program"

! Check that the compiler accepts -fsave-main-program:
! RUN: %flang_fc1 -emit-hlfir -fsave-main-program %s -o -
! CHECK: "-fc1"{{.*}}"-fsave-main-program"
1 change: 1 addition & 0 deletions flang/test/Lower/fsave-main-program.f90
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
! Test -fsave-main-program switch.
! RUN: %flang_fc1 -emit-hlfir -o - %s | FileCheck --check-prefix=CHECK-DEFAULT %s
! RUN: %flang_fc1 -fsave-main-program -emit-hlfir -o - %s | FileCheck --check-prefix=CHECK-SAVE %s
! RUN: %flang_fc1 -fsave-main-program -fno-save-main-program -emit-hlfir -o - %s | FileCheck --check-prefix=CHECK-DEFAULT %s
program test
integer :: i
call foo(i)
Expand Down
Loading