[flang-commits] [flang] 83b0d0f - [flang] fulfill -Msave/-fno-automatic in main programs too

Jean Perier via flang-commits flang-commits at lists.llvm.org
Tue Mar 15 01:34:34 PDT 2022


Author: Jean Perier
Date: 2022-03-15T09:33:07+01:00
New Revision: 83b0d0f964c0b50d452982e0362c7cbe44a51ad7

URL: https://github.com/llvm/llvm-project/commit/83b0d0f964c0b50d452982e0362c7cbe44a51ad7
DIFF: https://github.com/llvm/llvm-project/commit/83b0d0f964c0b50d452982e0362c7cbe44a51ad7.diff

LOG: [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

Added: 
    

Modified: 
    flang/lib/Evaluate/tools.cpp

Removed: 
    


################################################################################
diff  --git a/flang/lib/Evaluate/tools.cpp b/flang/lib/Evaluate/tools.cpp
index 48c638bcb9337..68b2a40d48c5d 100644
--- a/flang/lib/Evaluate/tools.cpp
+++ b/flang/lib/Evaluate/tools.cpp
@@ -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;


        


More information about the flang-commits mailing list