Skip to content

Commit 937cc7b

Browse files
committed
#3473 Consider loop control variable in Reference.is_write
1 parent ab467f9 commit 937cc7b

2 files changed

Lines changed: 8 additions & 0 deletions

File tree

src/psyclone/psyir/nodes/reference.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ def is_write(self):
131131
from psyclone.psyir.nodes.assignment import Assignment
132132
from psyclone.psyir.nodes.call import Call
133133
from psyclone.psyir.nodes.intrinsic_call import IntrinsicCall
134+
from psyclone.psyir.nodes.loop import Loop
134135
parent = self.parent
135136
# pure or inquiry IntrinsicCall nodes do not write to their arguments.
136137
if (isinstance(parent, IntrinsicCall) and (parent.is_inquiry or
@@ -144,6 +145,9 @@ def is_write(self):
144145
# The reference that is the LHS of an assignment is a write.
145146
if isinstance(parent, Assignment) and parent.lhs is self:
146147
return True
148+
# Loop control variable is also a write
149+
if isinstance(parent, Loop) and parent.variable_reference is self:
150+
return True
147151
return False
148152

149153
@property

src/psyclone/tests/psyir/nodes/reference_test.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -620,6 +620,8 @@ def test_reference_is_write(fortran_reader):
620620
a = SIN(c)
621621
call somecall(a)
622622
a = b
623+
do i=1,2
624+
enddo
623625
end subroutine"""
624626
psyir = fortran_reader.psyir_from_source(code)
625627
references = psyir.walk(Reference)
@@ -640,6 +642,8 @@ def test_reference_is_write(fortran_reader):
640642
# a = b has a as write and b as not
641643
assert references[10].is_write
642644
assert not references[11].is_write
645+
# Loop control variable
646+
assert references[12].is_write
643647

644648

645649
def test_reference_component_indices(fortran_reader):

0 commit comments

Comments
 (0)