Skip to content

Commit 57eecd5

Browse files
author
git apple-llvm automerger
committed
Merge commit '645c1ee8969c' from llvm.org/main into next
2 parents 1d3bc20 + 645c1ee commit 57eecd5

File tree

5 files changed

+25
-1
lines changed

5 files changed

+25
-1
lines changed

clang/include/clang/Driver/Options.td

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7094,6 +7094,9 @@ defm unsigned : OptInFC1FFlag<"unsigned", "Enables UNSIGNED type">;
70947094
def fno_automatic : Flag<["-"], "fno-automatic">, Group<f_Group>,
70957095
HelpText<"Implies the SAVE attribute for non-automatic local objects in subprograms unless RECURSIVE">;
70967096

7097+
def fsave_main_program : Flag<["-"], "fsave-main-program">, Group<f_Group>,
7098+
HelpText<"Place all variables from the main program in static memory (otherwise scalars may be placed on the stack)">;
7099+
70977100
defm stack_arrays : BoolOptionWithoutMarshalling<"f", "stack-arrays",
70987101
PosFlag<SetTrue, [], [ClangOption], "Attempt to allocate array temporaries on the stack, no matter their size">,
70997102
NegFlag<SetFalse, [], [ClangOption], "Allocate array temporaries on the heap (default)">>;

clang/lib/Driver/ToolChains/Flang.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,8 @@ void Flang::addFortranDialectOptions(const ArgList &Args,
5757
options::OPT_fno_automatic,
5858
options::OPT_fhermetic_module_files,
5959
options::OPT_frealloc_lhs,
60-
options::OPT_fno_realloc_lhs});
60+
options::OPT_fno_realloc_lhs,
61+
options::OPT_fsave_main_program});
6162
}
6263

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

flang/lib/Frontend/CompilerInvocation.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -766,6 +766,11 @@ static bool parseFrontendArgs(FrontendOptions &opts, llvm::opt::ArgList &args,
766766
opts.features.Enable(Fortran::common::LanguageFeature::DefaultSave);
767767
}
768768

769+
// -fsave-main-program
770+
if (args.hasArg(clang::driver::options::OPT_fsave_main_program)) {
771+
opts.features.Enable(Fortran::common::LanguageFeature::SaveMainProgram);
772+
}
773+
769774
if (args.hasArg(
770775
clang::driver::options::OPT_falternative_parameter_statement)) {
771776
opts.features.Enable(Fortran::common::LanguageFeature::OldStyleParameter);
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
! Check that the driver passes through -fsave-main-program:
2+
! RUN: %flang -### -S -fsave-main-program %s -o - 2>&1 | FileCheck %s
3+
! Check that the compiler accepts -fsave-main-program:
4+
! RUN: %flang_fc1 -emit-hlfir -fsave-main-program %s -o -
5+
! CHECK: "-fc1"{{.*}}"-fsave-main-program"
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
! Test -fsave-main-program switch.
2+
! RUN: %flang_fc1 -emit-hlfir -o - %s | FileCheck --check-prefix=CHECK-DEFAULT %s
3+
! RUN: %flang_fc1 -fsave-main-program -emit-hlfir -o - %s | FileCheck --check-prefix=CHECK-SAVE %s
4+
program test
5+
integer :: i
6+
call foo(i)
7+
end
8+
9+
!CHECK-DEFAULT-NOT: fir.global internal @_QFEi
10+
!CHECK-SAVE: fir.global internal @_QFEi

0 commit comments

Comments
 (0)