Author: Peter Klausler Date: 2025-05-09T13:22:30-07:00 New Revision: 8272e451613d8f929e3d9d0d28c3ca1b225b0000
URL: https://github.com/llvm/llvm-project/commit/8272e451613d8f929e3d9d0d28c3ca1b225b0000 DIFF: https://github.com/llvm/llvm-project/commit/8272e451613d8f929e3d9d0d28c3ca1b225b0000.diff LOG: [flang] Exempt construct entities from SAVE check for PURE (#131383) A PURE subprogram can't have a local variable with the SAVE attribute. An ASSOCIATE or SELECT TYPE construct entity whose selector is a variable will return true from IsSave(); exclude them from the local variable check. Fixes https://github.com/llvm/llvm-project/issues/131356. (cherry picked from commit b99dab25879449cb89c1ebd7b4088163543918e3) Added: Modified: flang/lib/Semantics/check-declarations.cpp flang/test/Semantics/call10.f90 Removed: ################################################################################ diff --git a/flang/lib/Semantics/check-declarations.cpp b/flang/lib/Semantics/check-declarations.cpp index 5c26469b9fa24..8da9252133bdc 100644 --- a/flang/lib/Semantics/check-declarations.cpp +++ b/flang/lib/Semantics/check-declarations.cpp @@ -359,7 +359,10 @@ void CheckHelper::Check(const Symbol &symbol) { // are not pertinent to the characteristics of the procedure. // Restrictions on entities in pure procedure interfaces don't need // enforcement. - } else if (!FindCommonBlockContaining(symbol) && IsSaved(symbol)) { + } else if (symbol.has<AssocEntityDetails>() || + FindCommonBlockContaining(symbol)) { + // can look like they have SAVE but are fine in PURE + } else if (IsSaved(symbol)) { if (IsInitialized(symbol)) { messages_.Say( "A pure subprogram may not initialize a variable"_err_en_US); diff --git a/flang/test/Semantics/call10.f90 b/flang/test/Semantics/call10.f90 index 2d2f57934cd8a..1e186f7b4048a 100644 --- a/flang/test/Semantics/call10.f90 +++ b/flang/test/Semantics/call10.f90 @@ -36,6 +36,8 @@ pure subroutine s05a end subroutine end interface + real :: moduleVar = 1. + contains subroutine impure(x) @@ -117,6 +119,8 @@ pure subroutine s05 ! C1589 !ERROR: A pure subprogram may not initialize a variable real :: v6 = 0. end block + associate (x => moduleVar) ! ok + end associate end subroutine pure subroutine s06 ! C1589 !ERROR: A pure subprogram may not have a variable with the VOLATILE attribute _______________________________________________ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits