From 663860f63e73518fc09e55a4a68b03f8027eafc8 Mon Sep 17 00:00:00 2001 From: Tim Keith Date: Mon, 22 Jun 2020 11:32:54 -0700 Subject: [PATCH] [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 --- flang/lib/Evaluate/tools.cpp | 2 +- flang/test/Semantics/resolve45.f90 | 9 ++++++++- 2 files changed, 9 insertions(+), 2 deletions(-) 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)