diff --git a/dace/frontend/fortran/ast_desugaring.py b/dace/frontend/fortran/ast_desugaring.py index 661872bd2b..cbaccd39f8 100644 --- a/dace/frontend/fortran/ast_desugaring.py +++ b/dace/frontend/fortran/ast_desugaring.py @@ -1966,17 +1966,19 @@ def _keep_from(node: Base): if ns in killed: continue ns_typ = find_type_of_entity(ns_node, alias_map) - if isinstance(ns_node, Entity_Decl) and ns_typ.pointer: - # If it is a pointer that we have decided to remove, then clear out all of its assignments. - for pa in walk(ast, Pointer_Assignment_Stmt): - dst = pa.children[0] - if not isinstance(dst, Name): - # TODO: Handle data-refs. - continue - dst_spec = search_real_local_alias_spec(dst, alias_map) - if dst_spec and alias_map[dst_spec] is ns_node: - remove_self(pa) if isinstance(ns_node, Entity_Decl): + if ns_typ.pointer: + # If it is a pointer that we have decided to remove, then clear out all of its assignments. + for pa in walk(ast, Pointer_Assignment_Stmt): + dst = pa.children[0] + if isinstance(dst, Name): + dst_spec = search_real_local_alias_spec(dst, alias_map) + else: + scope_spec = search_scope_spec(dst) + assert scope_spec + dst_spec = find_dataref_component_spec(dst, scope_spec, alias_map) + if dst_spec and alias_map[dst_spec] is ns_node: + remove_self(pa) elist = ns_node.parent remove_self(ns_node) # But there are many things to clean-up. @@ -2011,6 +2013,18 @@ def _keep_from(node: Base): if not elist_spart.children: remove_self(elist_spart) elif isinstance(ns_node, Component_Decl): + if ns_typ.pointer: + # If it is a pointer that we have decided to remove, then clear out all of its assignments. + for pa in walk(ast, Pointer_Assignment_Stmt): + dst = pa.children[0] + if isinstance(dst, Name): + dst_spec = search_real_local_alias_spec(dst, alias_map) + else: + scope_spec = search_scope_spec(dst) + assert scope_spec + dst_spec = find_dataref_component_spec(dst, scope_spec, alias_map) + if dst_spec and alias_map[dst_spec] is ns_node: + remove_self(pa) clist = ns_node.parent remove_self(ns_node) # But there are many things to clean-up. diff --git a/tests/fortran/ast_desugaring_test.py b/tests/fortran/ast_desugaring_test.py index b9dff85461..720817af2f 100644 --- a/tests/fortran/ast_desugaring_test.py +++ b/tests/fortran/ast_desugaring_test.py @@ -1586,6 +1586,7 @@ def test_pointer_pruning(): type T integer :: data(4) = 8 integer, pointer :: ptr(:) => null() + integer, pointer :: unused_T_ptr(:) => null() end type T end module lib