From e7d7acd68fa7d8c7598fdf904a56a51cefbec0ea Mon Sep 17 00:00:00 2001 From: Nick Gasson Date: Thu, 18 Jan 2024 11:29:57 +0000 Subject: [PATCH] Fix error getting resolved value of array-of-record signal Fixes #839 --- src/lower.c | 33 +++++++++------------------------ test/regress/issue839.vhd | 25 +++++++++++++++++++++++++ test/regress/testlist.txt | 1 + 3 files changed, 35 insertions(+), 24 deletions(-) create mode 100644 test/regress/issue839.vhd diff --git a/src/lower.c b/src/lower.c index ff76b427..88a4377b 100644 --- a/src/lower.c +++ b/src/lower.c @@ -3243,17 +3243,6 @@ static vcode_reg_t lower_external_name(lower_unit_t *lu, tree_t ref) return result_reg; } -static type_t lower_base_type(type_t type) -{ - for (type_t base; type_kind(type) == T_SUBTYPE; type = base) { - base = type_base(type); - if (type_ident(base) == type_ident(type)) - break; // Subtype created for constrained array definition - } - - return type; -} - static vcode_reg_t lower_resolved(lower_unit_t *lu, type_t type, vcode_reg_t reg) { @@ -3278,9 +3267,8 @@ static vcode_reg_t lower_resolved(lower_unit_t *lu, type_t type, // Use a helper function to convert a record signal into a record // containing the resolved values - type_t base = lower_base_type(type); - ident_t helper_func = - ident_prefix(type_ident(base), ident_new("resolved"), '$'); + ident_t base_id = type_ident(type_base_recur(type)); + ident_t helper_func = ident_prefix(base_id, ident_new("resolved"), '$'); vcode_reg_t arg_reg = reg; if (type_is_array(type)) { @@ -3290,7 +3278,7 @@ static vcode_reg_t lower_resolved(lower_unit_t *lu, type_t type, arg_reg = lower_wrap(lu, type, reg); } - vcode_type_t vrtype = lower_func_result_type(base); + vcode_type_t vrtype = lower_func_result_type(type); vcode_reg_t args[] = { lower_context_for_call(lu, helper_func), arg_reg }; return emit_fcall(helper_func, vrtype, vrtype, VCODE_CC_VHDL, args, 2); @@ -4551,9 +4539,8 @@ static void lower_new_record(lower_unit_t *lu, type_t type, else if (type_const_bounds(type)) emit_copy(dst_ptr, src_ptr, VCODE_INVALID_REG); else { - type_t base = lower_base_type(type); - ident_t helper_func = - ident_prefix(type_ident(base), ident_new("new"), '$'); + ident_t base_id = type_ident(type_base_recur(type)); + ident_t helper_func = ident_prefix(base_id, ident_new("new"), '$'); vcode_reg_t args[] = { lower_context_for_call(lu, helper_func), @@ -5991,9 +5978,8 @@ static void lower_copy_record(lower_unit_t *lu, type_t type, else if (lower_trivially_copyable(type)) emit_copy(dst_ptr, src_ptr, VCODE_INVALID_REG); else { - type_t base = lower_base_type(type); - ident_t helper_func = - ident_prefix(type_ident(base), ident_new("copy"), '$'); + ident_t base_id = type_ident(type_base_recur(type)); + ident_t helper_func = ident_prefix(base_id, ident_new("copy"), '$'); vcode_reg_t args[] = { lower_context_for_call(lu, helper_func), @@ -6023,9 +6009,8 @@ static void lower_copy_array(lower_unit_t *lu, type_t dst_type, type_t src_type, emit_copy(dst_data, src_data, count_reg); } else { - type_t base = lower_base_type(dst_type); - ident_t helper_func = - ident_prefix(type_ident(base), ident_new("copy"), '$'); + ident_t base_id = type_ident(type_base_recur(dst_type)); + ident_t helper_func = ident_prefix(base_id, ident_new("copy"), '$'); assert(vcode_reg_kind(dst_array) == VCODE_TYPE_UARRAY); assert(vcode_reg_kind(src_array) == VCODE_TYPE_UARRAY); diff --git a/test/regress/issue839.vhd b/test/regress/issue839.vhd new file mode 100644 index 00000000..a945d35b --- /dev/null +++ b/test/regress/issue839.vhd @@ -0,0 +1,25 @@ +entity issue839 is +end entity; + +architecture test of issue839 is + type t_rec is record + f : integer; + end record; + + type t_array is array (natural range <>) of t_rec; + subtype t_sub is t_array; + + signal s : t_sub(1 to 2); +begin + + check: process is + begin + -- This would call the wrong helper function + assert s = (1 to 2 => (f => integer'left)); + s(2).f <= 6; + wait for 0 ns; + assert s(2) = (f => 6); + wait; + end process; + +end architecture; diff --git a/test/regress/testlist.txt b/test/regress/testlist.txt index 80a6dc64..dc2744d4 100644 --- a/test/regress/testlist.txt +++ b/test/regress/testlist.txt @@ -924,3 +924,4 @@ issue827 normal,2008 cover22 shell issue831 normal,2008 issue829 normal +issue839 normal -- 2.39.2