Skip to content

Commit

Permalink
Fix another NEMO4 failure case
Browse files Browse the repository at this point in the history
  • Loading branch information
LonelyCat124 committed Jan 28, 2025
1 parent a897bf9 commit a840c8b
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/psyclone/psyir/transformations/scalarization_trans.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,16 +108,22 @@ def _is_local_array(signature: Signature,
'''
if not var_accesses[signature].is_array():
return False
# If any of the accesses are to a CodeBlock then we stop. This can
# happen if there is a string access inside a string concatenation,
# e.g. NEMO4.
for access in var_accesses[signature].all_accesses:
if isinstance(access.node, CodeBlock):
return False
base_symbol = var_accesses[signature].all_accesses[0].node.symbol
if not base_symbol.is_automatic:
return False

return True

@staticmethod
def _have_same_unmodified_index(signature: Signature,
var_accesses: VariablesAccessInfo) \
-> bool:
def _have_same_unmodified_index(
signature: Signature,
var_accesses: VariablesAccessInfo) -> bool:
'''
:param signature: The signature to check.
:param var_accesses: The VariableAccessesInfo object containing
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,13 @@ def test_scalararizationtrans_is_local_array(fortran_reader):
integer :: k
real, dimension(1:100) :: local
real, dimension(1:100) :: a
character(2), dimension(1:100) :: b
do i = 1, 100
arr(i) = i
a(i) = i
local(i) = i
b(i) = b(i) // "c"
end do
end subroutine'''
psyir = fortran_reader.psyir_from_source(code)
Expand All @@ -72,6 +74,14 @@ def test_scalararizationtrans_is_local_array(fortran_reader):
assert ScalarizationTrans._is_local_array(keys[3],
var_accesses)

# Test b - the RHS of the assignment is a codeblock so we do not
# count it as a local array and invalidate it, as otherwise the
# local array test can fail. Also we can't safely transform the
# CodeBlock anyway.
assert var_accesses[keys[4]].var_name == "b"
assert not ScalarizationTrans._is_local_array(keys[4],
var_accesses)

# Test filter behaviour same as used in the transformation
local_arrays = filter(
lambda sig: ScalarizationTrans._is_local_array(sig, var_accesses),
Expand Down

0 comments on commit a840c8b

Please sign in to comment.