[flang-commits] [flang] c2921d1 - [flang] SAVE statement should not apply to nested scoping units

Tim Keith via flang-commits flang-commits at lists.llvm.org
Sat Sep 26 12:42:52 PDT 2020


Author: Riccardo Bertossa
Date: 2020-09-26T12:42:14-07:00
New Revision: c2921d148e7b4e61794fa5498746ec0840861cf8

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

LOG: [flang] SAVE statement should not apply to nested scoping units

SAVE statement, according to 8.6.14, must apply to the same scoping
unit, that excludes nested scoping units. For example, if the SAVE
statement is found in a MODULE, the functions contained in that module
should not inherit the SAVE attribute. I think that the code was doing
this, failing the following source:

```
MODULE pippo
SAVE

CONTAINS
PURE FUNCTION fft_stick_index( )
   IMPLICIT NONE
   INTEGER :: fft_stick_index
   INTEGER :: mc  !error: A pure subprogram may not have a variable with the SAVE attribute
END FUNCTION

END MODULE
```

Differential Revision: https://reviews.llvm.org/D88279

Added: 
    flang/test/Semantics/save01.f90

Modified: 
    flang/lib/Evaluate/tools.cpp

Removed: 
    


################################################################################
diff  --git a/flang/lib/Evaluate/tools.cpp b/flang/lib/Evaluate/tools.cpp
index 4edf90d37fa5..567a3768b103 100644
--- a/flang/lib/Evaluate/tools.cpp
+++ b/flang/lib/Evaluate/tools.cpp
@@ -1004,12 +1004,8 @@ bool IsSaved(const Symbol &original) {
       return true;
     } else if (IsDummy(symbol) || IsFunctionResult(symbol)) {
       return false;
-    } else {
-      for (; !scope->IsGlobal(); scope = &scope->parent()) {
-        if (scope->hasSAVE()) {
-          return true;
-        }
-      }
+    } else if (scope->hasSAVE() ) {
+      return true;
     }
   }
   return false;

diff  --git a/flang/test/Semantics/save01.f90 b/flang/test/Semantics/save01.f90
new file mode 100644
index 000000000000..3c2ed581af97
--- /dev/null
+++ b/flang/test/Semantics/save01.f90
@@ -0,0 +1,21 @@
+! RUN: %S/test_errors.sh %s %t %f18
+MODULE test
+SAVE
+CONTAINS
+PURE FUNCTION pf( )
+   IMPLICIT NONE
+   INTEGER :: pf
+   INTEGER :: mc
+   !OK: SAVE statement is not inherited by the function
+END FUNCTION
+
+PURE FUNCTION pf2( )
+   IMPLICIT NONE
+   SAVE
+   INTEGER :: pf2
+   !ERROR: A pure subprogram may not have a variable with the SAVE attribute
+   INTEGER :: mc
+END FUNCTION
+
+END MODULE
+


        


More information about the flang-commits mailing list