[flang-commits] [flang] 663860f - [flang] Fix bug checking SAVE attribute

Tim Keith via flang-commits flang-commits at lists.llvm.org
Mon Jun 22 11:33:21 PDT 2020


Author: Tim Keith
Date: 2020-06-22T11:33:04-07:00
New Revision: 663860f63e73518fc09e55a4a68b03f8027eafc8

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

LOG: [flang] Fix bug checking SAVE attribute

Treat function result like dummy argument: a SAVE statement without an
entity-list does not make it saved.

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

Added: 
    

Modified: 
    flang/lib/Evaluate/tools.cpp
    flang/test/Semantics/resolve45.f90

Removed: 
    


################################################################################
diff  --git a/flang/lib/Evaluate/tools.cpp b/flang/lib/Evaluate/tools.cpp
index 3538cd587f97..16cc39f78291 100644
--- a/flang/lib/Evaluate/tools.cpp
+++ b/flang/lib/Evaluate/tools.cpp
@@ -1003,7 +1003,7 @@ bool IsSaved(const Symbol &original) {
     } else if (const Symbol * block{FindCommonBlockContaining(symbol)};
                block && block->attrs().test(Attr::SAVE)) {
       return true;
-    } else if (IsDummy(symbol)) {
+    } else if (IsDummy(symbol) || IsFunctionResult(symbol)) {
       return false;
     } else {
       for (; !scope->IsGlobal(); scope = &scope->parent()) {

diff  --git a/flang/test/Semantics/resolve45.f90 b/flang/test/Semantics/resolve45.f90
index 8ab75595d405..3e98ff662a17 100644
--- a/flang/test/Semantics/resolve45.f90
+++ b/flang/test/Semantics/resolve45.f90
@@ -15,8 +15,15 @@ function f2(x, y)
   !ERROR: SAVE attribute may not be applied to dummy argument 'x'
   complex, save :: x
   allocatable :: y
+  integer :: y
   !ERROR: SAVE attribute may not be applied to dummy argument 'y'
-  integer, save :: y
+  save :: y
+end
+
+! SAVE statement should not trigger the above errors
+function f2b(x, y)
+  real :: x, y
+  save
 end
 
 subroutine s3(x)


        


More information about the flang-commits mailing list