Index: flang/lib/Evaluate/tools.cpp =================================================================== --- flang/lib/Evaluate/tools.cpp +++ flang/lib/Evaluate/tools.cpp @@ -1004,12 +1004,8 @@ return true; } else if (IsDummy(symbol) || IsFunctionResult(symbol)) { return false; - } else { - for (; !scope->IsGlobal(); scope = &scope->parent()) { - if (scope->hasSAVE()) { - return true; - } - } + } else if (scope->hasSAVE() ) { + return true; } } return false; Index: flang/test/Semantics/save01.f90 =================================================================== --- /dev/null +++ flang/test/Semantics/save01.f90 @@ -0,0 +1,21 @@ +! RUN: %S/test_errors.sh %s %t %f18 +MODULE test +SAVE +CONTAINS +PURE FUNCTION pf( ) + IMPLICIT NONE + INTEGER :: pf + INTEGER :: mc + !OK: SAVE statement is not inherited by the function +END FUNCTION + +PURE FUNCTION pf2( ) + IMPLICIT NONE + SAVE + INTEGER :: pf2 + INTEGER :: mc + !ERROR: A pure subprogram may not have a variable with the SAVE attribute +END FUNCTION + +END MODULE +