From 1799000e7edbc4f2425f62a6144769299ccb3cae Mon Sep 17 00:00:00 2001 From: Nick Gasson Date: Sat, 17 Feb 2024 18:02:29 +0000 Subject: [PATCH] Fix crash in port conversion for array-of-array --- src/lower.c | 5 +++-- test/regress/conv14.vhd | 43 +++++++++++++++++++++++++++++++++++++++ test/regress/testlist.txt | 1 + 3 files changed, 47 insertions(+), 2 deletions(-) create mode 100644 test/regress/conv14.vhd diff --git a/src/lower.c b/src/lower.c index 31f8fea5..29f481d9 100644 --- a/src/lower.c +++ b/src/lower.c @@ -11323,6 +11323,7 @@ static ident_t lower_converter(lower_unit_t *parent, tree_t expr, const tree_kind_t kind = tree_kind(expr); tree_t fdecl = kind == T_CONV_FUNC ? tree_ref(expr) : NULL; bool p0_uarray = false, r_uarray = false; + type_t p0_type = NULL; // Detect some trivial cases and avoid generating a conversion function if (kind == T_TYPE_CONV && type_is_array(atype) && type_is_array(rtype)) { @@ -11332,7 +11333,7 @@ static ident_t lower_converter(lower_unit_t *parent, tree_t expr, else if (kind == T_TYPE_CONV && type_is_enum(atype) && type_is_enum(rtype)) return NULL; else if (kind == T_CONV_FUNC) { - type_t p0_type = tree_type(tree_port(fdecl, 0)); + p0_type = tree_type(tree_port(fdecl, 0)); p0_uarray = type_is_array(p0_type) && !type_const_bounds(p0_type); r_uarray = type_is_array(rtype) && !type_const_bounds(rtype); @@ -11406,7 +11407,7 @@ static ident_t lower_converter(lower_unit_t *parent, tree_t expr, else { vcode_reg_t arg_reg = p0; if (p0_uarray) - arg_reg = lower_wrap(lu, atype, p0); + arg_reg = lower_coerce_arrays(lu, atype, p0_type, p0); ident_t func = tree_ident2(fdecl); vcode_reg_t context_reg = lower_context_for_call(lu, func); diff --git a/test/regress/conv14.vhd b/test/regress/conv14.vhd new file mode 100644 index 00000000..6521584d --- /dev/null +++ b/test/regress/conv14.vhd @@ -0,0 +1,43 @@ +entity conv14 is +end entity; + +architecture test of conv14 is + type t_bv_array is array (natural range <>) of bit_vector; + + function "not" (x : t_bv_array) return t_bv_array is + variable r : x'subtype; + begin + for i in x'range loop + for j in x(x'left)'range loop + r(i)(j) := not x(i)(j); + end loop; + end loop; + return r; + end function; + + signal s : t_bv_array(1 to 2)(1 to 2); + +begin + + b: block is + port ( p : t_bv_array(1 to 2)(1 to 2) ); + port map ( p => "not"(s) ); + begin + + check: process is + begin + assert p = ("11", "11"); + wait for 0 ns; + assert p = ("01", "10"); + wait; + end process; + + end block; + + stim: process is + begin + s <= ("10", "01"); + wait; + end process; + +end architecture; diff --git a/test/regress/testlist.txt b/test/regress/testlist.txt index 7f09e495..6f35a8cd 100644 --- a/test/regress/testlist.txt +++ b/test/regress/testlist.txt @@ -940,3 +940,4 @@ driver20 normal driver21 fail,gold ename7 normal,2008 issue844 normal,2008 +conv14 normal,2008 -- 2.39.2