From 358f04e256e58132c08e77cbdaaad25749656ec9 Mon Sep 17 00:00:00 2001 From: Nick Gasson Date: Wed, 30 Nov 2022 22:22:21 +0000 Subject: [PATCH] Fix crash analysing OSVVM MemoryGenericPkg. Issue #577 --- src/lower.c | 10 +++++++--- test/regress/issue577.vhd | 28 ++++++++++++++++++++++++++++ test/regress/testlist.txt | 1 + 3 files changed, 36 insertions(+), 3 deletions(-) create mode 100644 test/regress/issue577.vhd diff --git a/src/lower.c b/src/lower.c index 49cbbe9c..f11da8fe 100644 --- a/src/lower.c +++ b/src/lower.c @@ -158,6 +158,7 @@ static vcode_reg_t lower_constraints(tree_t *cons, int count, int max); static vcode_reg_t lower_lvalue(tree_t expr); static vcode_reg_t lower_rvalue(tree_t expr); static bool lower_is_signal_ref(tree_t expr); +static vcode_reg_t lower_rewrap(vcode_reg_t data, vcode_reg_t bounds); typedef vcode_reg_t (*lower_signal_flag_fn_t)(vcode_reg_t, vcode_reg_t); typedef vcode_reg_t (*arith_fn_t)(vcode_reg_t, vcode_reg_t); @@ -768,11 +769,14 @@ static vcode_reg_t lower_wrap_with_new_bounds(type_t type, vcode_reg_t array, { assert(type_is_array(type)); + if (type_is_unconstrained(type)) + return lower_rewrap(lower_array_data(data), array); + const int ndims = lower_dims_for_type(type); vcode_dim_t dims[ndims]; int dptr = 0; - if (standard() >= STD_08 && type_kind(type) == T_SUBTYPE) { + if (standard() >= STD_08) { tree_t cons[MAX_CONSTRAINTS]; int ncons = pack_constraints(type, cons); @@ -1561,9 +1565,9 @@ static int32_t lower_toggle_tag_for(type_t type, tree_t where, ident_t prefix, } while (1) { - char arr_index[16] = {0}; + char arr_index[16]; int32_t tmp = -1; - checked_sprintf(arr_index, sizeof(arr_index), "(%lu)", i); + checked_sprintf(arr_index, sizeof(arr_index), "(%"PRIi64")", i); ident_t arr_suffix = ident_prefix(prefix, ident_new(arr_index), '\0'); // On lowest dimension walk through elements, if elements are arrays, diff --git a/test/regress/issue577.vhd b/test/regress/issue577.vhd new file mode 100644 index 00000000..6e455da2 --- /dev/null +++ b/test/regress/issue577.vhd @@ -0,0 +1,28 @@ +entity issue577 is +end entity; + +architecture test of issue577 is + + type mem_t is array (natural range <>) of bit_vector; + type mem_ptr_t is access mem_t; + + function init_mem return mem_t is + variable mem : mem_t(1 to 3)(1 to 5); + begin + return mem; + end function; + +begin + + p1: process is + variable ptr : mem_ptr_t; + begin + ptr := new mem_t'(init_mem); + ptr(2)(2) := '1'; + wait for 1 ns; + assert ptr(2)(2) = '1'; + assert ptr(2)(3) = '0'; + wait; + end process; + +end architecture; diff --git a/test/regress/testlist.txt b/test/regress/testlist.txt index 3aaccd79..a69a37ab 100644 --- a/test/regress/testlist.txt +++ b/test/regress/testlist.txt @@ -697,3 +697,4 @@ cover3 cover,shell cover4 cover,shell cover5 cover,shell cover6 cover,shell +issue577 normal,2008 -- 2.39.2