Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 24 additions & 10 deletions dace/frontend/fortran/ast_desugaring.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand 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.
Expand Down
1 change: 1 addition & 0 deletions tests/fortran/ast_desugaring_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down