Skip to content

Commit 8272e45

Browse files
klauslertstellar
authored andcommitted
[flang] Exempt construct entities from SAVE check for PURE (llvm#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 llvm#131356. (cherry picked from commit b99dab2)
1 parent 069ef67 commit 8272e45

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

flang/lib/Semantics/check-declarations.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,10 @@ void CheckHelper::Check(const Symbol &symbol) {
359359
// are not pertinent to the characteristics of the procedure.
360360
// Restrictions on entities in pure procedure interfaces don't need
361361
// enforcement.
362-
} else if (!FindCommonBlockContaining(symbol) && IsSaved(symbol)) {
362+
} else if (symbol.has<AssocEntityDetails>() ||
363+
FindCommonBlockContaining(symbol)) {
364+
// can look like they have SAVE but are fine in PURE
365+
} else if (IsSaved(symbol)) {
363366
if (IsInitialized(symbol)) {
364367
messages_.Say(
365368
"A pure subprogram may not initialize a variable"_err_en_US);

flang/test/Semantics/call10.f90

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ pure subroutine s05a
3636
end subroutine
3737
end interface
3838

39+
real :: moduleVar = 1.
40+
3941
contains
4042

4143
subroutine impure(x)
@@ -117,6 +119,8 @@ pure subroutine s05 ! C1589
117119
!ERROR: A pure subprogram may not initialize a variable
118120
real :: v6 = 0.
119121
end block
122+
associate (x => moduleVar) ! ok
123+
end associate
120124
end subroutine
121125
pure subroutine s06 ! C1589
122126
!ERROR: A pure subprogram may not have a variable with the VOLATILE attribute

0 commit comments

Comments
 (0)