From 2af52eb824717abc1731e14824a1ca2b7ebb66d3 Mon Sep 17 00:00:00 2001 From: Nick Gasson Date: Thu, 12 May 2016 22:12:51 +0100 Subject: [PATCH] Fix segfault in memcpy introduced by earlier commit --- src/lower.c | 13 +++++----- test/regress/jcore5.vhd | 50 +++++++++++++++++++++++++++++++++++++++ test/regress/testlist.txt | 1 + 3 files changed, 58 insertions(+), 6 deletions(-) create mode 100644 test/regress/jcore5.vhd diff --git a/src/lower.c b/src/lower.c index 71465083..7944b63e 100644 --- a/src/lower.c +++ b/src/lower.c @@ -280,8 +280,6 @@ static vcode_reg_t lower_array_total_len(type_t type, vcode_reg_t reg) type_t elem = type_elem(type); if (type_is_array(elem)) return emit_mul(total, lower_array_total_len(elem, VCODE_INVALID_REG)); - else if (type_is_record(elem)) - return emit_mul(total, emit_const(vtype_offset(), type_width(elem))); else return total; } @@ -2821,12 +2819,15 @@ static void lower_sched_event(tree_t on, bool is_static) assert(false); } - if (array) + if (array) { + type_t elem = type_elem(type); n_elems = lower_array_total_len(type, nets); - else if (type_is_record(type)) - n_elems = emit_const(vtype_offset(), type_width(type)); + if (type_is_record(elem)) + n_elems = emit_mul(n_elems, + emit_const(vtype_offset(), type_width(elem))); + } else - n_elems = emit_const(vtype_offset(), 1); + n_elems = emit_const(vtype_offset(), type_width(type)); if (array && !lower_const_bounds(type)) { // Unwrap the meta-data to get nets array diff --git a/test/regress/jcore5.vhd b/test/regress/jcore5.vhd new file mode 100644 index 00000000..d83e74cf --- /dev/null +++ b/test/regress/jcore5.vhd @@ -0,0 +1,50 @@ +package cpu2j0_pack is + type cpu_debug_o_t is record + ack : bit; + d : bit_vector(31 downto 0); + rdy : bit; + end record; + + constant bits_exp : natural := 5; + constant bits : natural := 2**bits_exp; + + type bus_val_t is record + en : bit; + d : bit_vector(bits-1 downto 0); + end record; + + constant BUS_VAL_RESET : bus_val_t := ('0', (others => '0')); + + type ybus_val_pipeline_t is array (2 downto 0) of bus_val_t; + + type datapath_reg_t is record + debug_o : cpu_debug_o_t; + ybus_override : ybus_val_pipeline_t; + end record; + + constant DATAPATH_RESET : datapath_reg_t := ( + debug_o => (ack => '0', d => (others => '0'), rdy => '0'), + ybus_override => (others => BUS_VAL_RESET) ); + +end package; + +------------------------------------------------------------------------------- + +entity jcore5 is +end entity; + +use work.cpu2j0_pack.all; + +architecture test of jcore5 is + signal x : datapath_reg_t := DATAPATH_RESET; +begin + + process is + begin + assert x = ( + debug_o => (ack => '0', d => (others => '0'), rdy => '0'), + ybus_override => (others => BUS_VAL_RESET) ); + wait; + end process; + +end architecture; diff --git a/test/regress/testlist.txt b/test/regress/testlist.txt index 1ee94968..eac6bc32 100644 --- a/test/regress/testlist.txt +++ b/test/regress/testlist.txt @@ -315,3 +315,4 @@ jcore2 normal assert5 normal jcore3 normal jcore4 normal +jcore5 normal -- 2.39.2