Skip to content

Commit

Permalink
[flang] fulfill -Msave/-fno-automatic in main programs too
Browse files Browse the repository at this point in the history
`semantics::IsSaved()` was not applying -Msave/-fno-automatic for main programs.
This caused issues since lowering relies on it to allocate static
variables. This did not match nvfortran/gfortran behaviors where
-fno-automatic/-Msave control the static allocation of scalars in
main programs.

Some program may rely on main program scalars to be statically allocated in
bss (and therefore initialized to zero) with -Msave/-fno-automatic
flags.

Differential Revision: https://reviews.llvm.org/D121603
  • Loading branch information
jeanPerier committed Mar 15, 2022
1 parent 76b1601 commit 83b0d0f
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions flang/lib/Evaluate/tools.cpp
Expand Up @@ -1324,12 +1324,14 @@ bool IsSaved(const Symbol &original) {
// BLOCK DATA entities must all be in COMMON,
// which was checked above.
return true;
} else if (scope.kind() == Scope::Kind::Subprogram &&
scope.context().languageFeatures().IsEnabled(
common::LanguageFeature::DefaultSave) &&
!(scope.symbol() && scope.symbol()->attrs().test(Attr::RECURSIVE))) {
// -fno-automatic/-save/-Msave option applies to objects in
// executable subprograms unless they are explicitly RECURSIVE.
} else if (scope.context().languageFeatures().IsEnabled(
common::LanguageFeature::DefaultSave) &&
(scopeKind == Scope::Kind::MainProgram ||
(scope.kind() == Scope::Kind::Subprogram &&
!(scope.symbol() &&
scope.symbol()->attrs().test(Attr::RECURSIVE))))) {
// -fno-automatic/-save/-Msave option applies to all objects in executable
// main programs and subprograms unless they are explicitly RECURSIVE.
return true;
} else if (symbol.test(Symbol::Flag::InDataStmt)) {
return true;
Expand Down

0 comments on commit 83b0d0f

Please sign in to comment.