diff --git a/flang/lib/Evaluate/tools.cpp b/flang/lib/Evaluate/tools.cpp --- a/flang/lib/Evaluate/tools.cpp +++ b/flang/lib/Evaluate/tools.cpp @@ -1003,7 +1003,7 @@ } 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 --- a/flang/test/Semantics/resolve45.f90 +++ b/flang/test/Semantics/resolve45.f90 @@ -15,8 +15,15 @@ !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)