From ce58e0c8091935d6567a17f8e0a2c7c5ab391b3c Mon Sep 17 00:00:00 2001 From: Andrew Porter Date: Wed, 8 Jan 2025 14:33:41 +0000 Subject: [PATCH] #2271 extend ScopingNode.reference_accesses to handle UnsupportedFortranType --- src/psyclone/psyir/nodes/scoping_node.py | 6 +++- .../tests/psyir/nodes/scoping_node_test.py | 30 +++++++++++++++++-- 2 files changed, 33 insertions(+), 3 deletions(-) diff --git a/src/psyclone/psyir/nodes/scoping_node.py b/src/psyclone/psyir/nodes/scoping_node.py index 437a8f8819..ba6c2d0c0c 100644 --- a/src/psyclone/psyir/nodes/scoping_node.py +++ b/src/psyclone/psyir/nodes/scoping_node.py @@ -40,7 +40,7 @@ from psyclone.psyir.nodes.node import Node from psyclone.psyir.symbols import ( ArrayType, DataType, DataTypeSymbol, RoutineSymbol, StructureType, Symbol, - SymbolError, SymbolTable) + SymbolError, SymbolTable, UnsupportedFortranType) class ScopingNode(Node): @@ -217,6 +217,10 @@ def _get_accesses(dtype: DataType, info: VariablesAccessInfo): if isinstance(dim, ArrayType.ArrayBounds): dim.lower.reference_accesses(access_info) dim.upper.reference_accesses(access_info) + elif (isinstance(dtype, UnsupportedFortranType) and + dtype.partial_datatype): + # Recurse to examine partial datatype information. + _get_accesses(dtype.partial_datatype, info) # Examine the datatypes and initial values of all DataSymbols. for sym in self._symbol_table.datasymbols: diff --git a/src/psyclone/tests/psyir/nodes/scoping_node_test.py b/src/psyclone/tests/psyir/nodes/scoping_node_test.py index 4811d2960f..1199fa2999 100644 --- a/src/psyclone/tests/psyir/nodes/scoping_node_test.py +++ b/src/psyclone/tests/psyir/nodes/scoping_node_test.py @@ -43,7 +43,8 @@ Routine, ArrayReference) from psyclone.psyir.symbols import ( ArrayType, ArgumentInterface, DataSymbol, DataTypeSymbol, INTEGER_TYPE, - ScalarType, StructureType, Symbol, SymbolTable, REAL_TYPE) + REAL_TYPE, ScalarType, StructureType, Symbol, SymbolTable, + UnsupportedFortranType) from psyclone.tests.utilities import Compile @@ -345,7 +346,7 @@ def test_reference_accesses_struct(): def test_reference_accesses_array(): - '''Test reference_accesses() with the associated SymbolTable contains + '''Test reference_accesses() when the associated SymbolTable contains an array with dimensions that make reference to another Symbol. ''' @@ -367,3 +368,28 @@ def test_reference_accesses_array(): assert Signature("i_def") in vai.all_signatures assert Signature("r_def") in vai.all_signatures assert Signature("var2") in vai.all_signatures + + +def test_reference_accesses_unknown_type(): + '''Test reference_accesses() when the symbol table contains a symbol + of UnsupportedFortranType but with partial type information. + + ''' + sched = Schedule() + table = sched.symbol_table + # Create partial type information - an array of specified precision + # with an extent specified by another symbol. + rdef = table.new_symbol("r_def", symbol_type=DataSymbol, + datatype=INTEGER_TYPE) + big_sym = table.new_symbol("big", symbol_type=DataSymbol, + datatype=INTEGER_TYPE) + real_type = ScalarType(ScalarType.Intrinsic.REAL, rdef) + ptype = ArrayType(real_type, [Reference(big_sym)]) + utype = UnsupportedFortranType( + "real(r_def), dimension(big), target :: array", + partial_datatype=ptype) + table.new_symbol("array", symbol_type=DataSymbol, datatype=utype) + vai = VariablesAccessInfo() + sched.reference_accesses(vai) + assert Signature("r_def") in vai.all_signatures + assert Signature("big") in vai.all_signatures