Skip to content

Commit 32102b7

Browse files
committed
[flang] fulfill -Msave/-fno-automatic in main programs too
`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
1 parent bf39f57 commit 32102b7

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

flang/lib/Evaluate/tools.cpp

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1324,12 +1324,14 @@ bool IsSaved(const Symbol &original) {
13241324
// BLOCK DATA entities must all be in COMMON,
13251325
// which was checked above.
13261326
return true;
1327-
} else if (scope.kind() == Scope::Kind::Subprogram &&
1328-
scope.context().languageFeatures().IsEnabled(
1329-
common::LanguageFeature::DefaultSave) &&
1330-
!(scope.symbol() && scope.symbol()->attrs().test(Attr::RECURSIVE))) {
1331-
// -fno-automatic/-save/-Msave option applies to objects in
1332-
// executable subprograms unless they are explicitly RECURSIVE.
1327+
} else if (scope.context().languageFeatures().IsEnabled(
1328+
common::LanguageFeature::DefaultSave) &&
1329+
(scopeKind == Scope::Kind::MainProgram ||
1330+
(scope.kind() == Scope::Kind::Subprogram &&
1331+
!(scope.symbol() &&
1332+
scope.symbol()->attrs().test(Attr::RECURSIVE))))) {
1333+
// -fno-automatic/-save/-Msave option applies to all objects in executable
1334+
// main programs and subprograms unless they are explicitly RECURSIVE.
13331335
return true;
13341336
} else if (symbol.test(Symbol::Flag::InDataStmt)) {
13351337
return true;

0 commit comments

Comments
 (0)