From 1bf3d37eccc315d5bd3d564875f2d0150e16df23 Mon Sep 17 00:00:00 2001 From: Nick Gasson Date: Sun, 23 Oct 2022 17:56:31 +0100 Subject: [PATCH] Fix crash with signal containing unconstrained array. Issue #539 --- src/lower.c | 9 +++++---- test/regress/gold/record38.txt | 1 + test/regress/record38.vhd | 26 ++++++++++++++++++++++++++ test/regress/testlist.txt | 1 + 4 files changed, 33 insertions(+), 4 deletions(-) create mode 100644 test/regress/gold/record38.txt create mode 100644 test/regress/record38.vhd diff --git a/src/lower.c b/src/lower.c index 33bfbeb8..f3e5277c 100644 --- a/src/lower.c +++ b/src/lower.c @@ -6573,8 +6573,10 @@ static void lower_sub_signals(type_t type, tree_t where, tree_t *cons, // Array of non-homogeneous type (e.g. records). Need a loop to // initialise each sub-signal. + type_t elem = lower_elem_recur(type); + if (null_reg == VCODE_INVALID_REG) - null_reg = emit_null(vcode_reg_type(init_reg)); + null_reg = emit_null(vtype_pointer(lower_type(elem))); if (sig_ptr == VCODE_INVALID_REG) sig_ptr = emit_index(sig_var, VCODE_INVALID_REG); @@ -6587,6 +6589,8 @@ static void lower_sub_signals(type_t type, tree_t where, tree_t *cons, shift_constraints(&cons, &ncons, count); } + lower_check_array_sizes(where, type, init_type, bounds_reg, init_reg); + const int ndims = dimension_of(type); vcode_reg_t len_reg = lower_array_len(type, 0, bounds_reg); for (int i = 1; i < ndims; i++) @@ -6594,7 +6598,6 @@ static void lower_sub_signals(type_t type, tree_t where, tree_t *cons, if (lower_have_uarray_ptr(sig_ptr)) { // Need to allocate separate memory for the array - type_t elem = lower_elem_recur(type); vcode_type_t vtype = lower_signal_type(elem); vcode_type_t vbounds = lower_bounds(elem); vcode_reg_t mem_reg = emit_alloc(vtype, vbounds, len_reg); @@ -6630,8 +6633,6 @@ static void lower_sub_signals(type_t type, tree_t where, tree_t *cons, vcode_select_block(body_bb); - type_t elem = lower_elem_recur(type); - vcode_reg_t ptr_reg = emit_array_ref(sig_ptr, i_reg); vcode_reg_t data_reg = emit_array_ref(lower_array_data(init_reg), i_reg); vcode_reg_t null_off_reg = emit_array_ref(null_reg, i_reg); diff --git a/test/regress/gold/record38.txt b/test/regress/gold/record38.txt new file mode 100644 index 00000000..ca22bfb4 --- /dev/null +++ b/test/regress/gold/record38.txt @@ -0,0 +1 @@ +(init): value length 2 does not match signal S length 1 diff --git a/test/regress/record38.vhd b/test/regress/record38.vhd new file mode 100644 index 00000000..27be324a --- /dev/null +++ b/test/regress/record38.vhd @@ -0,0 +1,26 @@ +package my_package is + type my_type_t is record + state : bit_vector; + aux : bit_vector; + end record my_type_t; + + type my_array_t is array (natural range <>) of my_type_t; +end package my_package; + +------------------------------------------------------------------------------- + +entity record38 is +end entity; + +use work.my_package.all; + +architecture test of record38 is + function init return my_array_t is + begin + return (0 => (state => "101", aux => "1"), 1 => (state => "1", aux => "1")); + end function; + + signal s : my_array_t(0 to 0)(state(1 to 3), aux(1 to 1)) := init; +begin + +end architecture; diff --git a/test/regress/testlist.txt b/test/regress/testlist.txt index 89b3b048..34d64b21 100644 --- a/test/regress/testlist.txt +++ b/test/regress/testlist.txt @@ -686,3 +686,4 @@ signal28 normal,relaxed issue549 normal case14 normal,2008 cmdline4 shell +record38 fail,gold,2008 -- 2.39.2