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)