Skip to content

Commit

Permalink
Fix inquiry behaviour for is_read
Browse files Browse the repository at this point in the history
  • Loading branch information
LonelyCat124 committed Feb 4, 2025
1 parent 88c1eb3 commit 453a56b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/psyclone/psyir/nodes/reference.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,17 @@ def is_read(self):
'''
# pylint: disable=import-outside-toplevel
from psyclone.psyir.nodes.assignment import Assignment
from psyclone.psyir.nodes.intrinsic_call import IntrinsicCall
parent = self.parent
if isinstance(parent, Assignment):
if parent.lhs is self:
return False

# If we have an intrinsic call parent then we need to check if its
# an inquiry. Inquiry functions don't read from their arguments.
if isinstance(parent, IntrinsicCall) and parent.is_inquiry:
return False

# All references other than LHS of assignments represent a read. This
# can be improved in the future by looking at Call intents.
return True
Expand Down
3 changes: 3 additions & 0 deletions src/psyclone/tests/psyir/nodes/reference_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -583,6 +583,7 @@ def test_reference_is_read(fortran_reader):
code = """subroutine my_subroutine()
b = a
call somecall(c)
b = lbound(d)
end subroutine"""

psyir = fortran_reader.psyir_from_source(code)
Expand All @@ -591,6 +592,8 @@ def test_reference_is_read(fortran_reader):
assert references[1].is_read
assert references[3].symbol.name == "c"
assert references[3].is_read
assert references[6].symbol.name == "d"
assert not references[6].is_read


def test_reference_is_write(fortran_reader):
Expand Down

0 comments on commit 453a56b

Please sign in to comment.