Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
3 changes: 3 additions & 0 deletions clang/include/clang/Driver/Options.td
Original file line number Diff line number Diff line change
Expand Up @@ -6945,6 +6945,9 @@ 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 scalar may be placed on the stack)">;

defm stack_arrays : BoolOptionWithoutMarshalling<"f", "stack-arrays",
PosFlag<SetTrue, [], [ClangOption], "Attempt to allocate array temporaries on the stack, no matter their size">,
NegFlag<SetFalse, [], [ClangOption], "Allocate array temporaries on the heap (default)">>;
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 @@ -57,7 +57,8 @@ void Flang::addFortranDialectOptions(const ArgList &Args,
options::OPT_fno_automatic,
options::OPT_fhermetic_module_files,
options::OPT_frealloc_lhs,
options::OPT_fno_realloc_lhs});
options::OPT_fno_realloc_lhs,
options::OPT_fsave_main_program});
}

void Flang::addPreprocessingOptions(const ArgList &Args,
Expand Down
5 changes: 5 additions & 0 deletions flang/lib/Frontend/CompilerInvocation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -766,6 +766,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);
}

if (args.hasArg(
clang::driver::options::OPT_falternative_parameter_statement)) {
opts.features.Enable(Fortran::common::LanguageFeature::OldStyleParameter);
Expand Down
5 changes: 5 additions & 0 deletions flang/test/Driver/fsave-main-program.f90
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
! Check that the driver passes through -fsave-main-program:
! RUN: %flang -### -S -fsave-main-program %s -o - 2>&1 | FileCheck %s
! Check that the compiler accepts -fsave-main-program:
! RUN: %flang_fc1 -emit-hlfir -fsave-main-program %s -o -
! CHECK: "-fc1"{{.*}}"-fsave-main-program"
10 changes: 10 additions & 0 deletions flang/test/Lower/fsave-main-program.f90
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
! 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
program test
integer :: i
call foo(i)
end

!CHECK-DEFAULT-NOT: fir.global internal @_QFEi
!CHECK-SAVE: fir.global internal @_QFEi
Loading