Skip to content

[flang] Exempt construct entities from SAVE check for PURE #131383

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 19, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion flang/lib/Semantics/check-declarations.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,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);
Expand Down
4 changes: 4 additions & 0 deletions flang/test/Semantics/call10.f90
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ pure subroutine s05a
end subroutine
end interface

real :: moduleVar = 1.

contains

subroutine impure(x)
Expand Down Expand Up @@ -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
Expand Down