Skip to content

Commit 68aa07f

Browse files
committed
Dataflow: indirect addressing in CallStatement arguments now handled correctly
1 parent a204443 commit 68aa07f

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

loki/analyse/analyse_dataflow.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -232,9 +232,9 @@ def visit_CallStatement(self, o, **kwargs):
232232
outvals = [val for arg, val in o.arg_iter() if str(arg.type.intent).lower() in ('inout', 'out')]
233233
invals = [val for arg, val in o.arg_iter() if str(arg.type.intent).lower() in ('inout', 'in')]
234234

235+
arrays = [v for v in FindVariables().visit(outvals) if isinstance(v, Array)]
236+
dims = set(v for a in arrays for v in self._symbols_from_expr(a.dimensions))
235237
for val in outvals:
236-
arrays = [v for v in FindVariables().visit(outvals) if isinstance(v, Array)]
237-
dims = set(v for a in arrays for v in FindVariables().visit(a.dimensions))
238238
exprs = self._symbols_from_expr(val)
239239
defines |= {e for e in exprs if not e in dims}
240240
uses |= dims

loki/analyse/tests/test_analyse_dataflow.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -464,26 +464,30 @@ def test_analyse_call_args_array_slicing(frontend):
464464
465465
end subroutine random_call
466466
467-
subroutine test(v,n)
467+
subroutine test(v,n,b)
468468
implicit none
469469
470470
integer,intent(out) :: v(:)
471471
integer,intent( in) :: n
472+
integer,intent( in) :: b(n)
472473
473474
call random_call(v(n))
475+
call random_call(v(b(1)))
474476
475477
end subroutine test
476478
""".strip()
477479

478480
source = Sourcefile.from_source(fcode, frontend=frontend)
479481
routine = source['test']
480482

481-
call = FindNodes(CallStatement).visit(routine.body)[0]
483+
calls = FindNodes(CallStatement).visit(routine.body)
482484
routine.enrich(source.all_subroutines)
483485

484486
with dataflow_analysis_attached(routine):
485-
assert 'n' in call.uses_symbols
486-
assert not 'n' in call.defines_symbols
487+
assert 'n' in calls[0].uses_symbols
488+
assert not 'n' in calls[0].defines_symbols
489+
assert 'b' in calls[1].uses_symbols
490+
assert not 'b' in calls[0].defines_symbols
487491

488492

489493
@pytest.mark.parametrize('frontend', available_frontends())

0 commit comments

Comments
 (0)