diff --git a/flang/lib/Semantics/check-declarations.cpp b/flang/lib/Semantics/check-declarations.cpp --- a/flang/lib/Semantics/check-declarations.cpp +++ b/flang/lib/Semantics/check-declarations.cpp @@ -284,7 +284,7 @@ "A dummy argument may not have the SAVE attribute"_err_en_US); } } else if (IsFunctionResult(symbol)) { - if (IsSaved(symbol)) { + if (symbol.attrs().test(Attr::SAVE)) { messages_.Say( "A function result may not have the SAVE attribute"_err_en_US); } 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)