Skip to content

Commit

Permalink
Fix assertion failure when scalar signal has subtype with non-static …
Browse files Browse the repository at this point in the history
…bounds

Issue #972
  • Loading branch information
nickg committed Sep 20, 2024
1 parent 47ac610 commit 380d593
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 2 deletions.
1 change: 0 additions & 1 deletion src/lower.c
Original file line number Diff line number Diff line change
Expand Up @@ -7673,7 +7673,6 @@ static void lower_sub_signals(lower_unit_t *lu, type_t type, type_t var_type,
lower_check_scalar_bounds(lu, init_reg, type, where, where);

assert(!has_scope);
assert(bounds_reg == VCODE_INVALID_REG);

well_known_t wk = is_well_known(type_ident(type_base_recur(type)));
if (wk == W_IEEE_ULOGIC || wk == W_IEEE_LOGIC)
Expand Down
2 changes: 1 addition & 1 deletion src/vcode.c
Original file line number Diff line number Diff line change
Expand Up @@ -5727,7 +5727,7 @@ void emit_pop_scope(void)
vcode_reg_t emit_debug_locus(ident_t unit, ptrdiff_t offset)
{
VCODE_FOR_EACH_MATCHING_OP(other, VCODE_OP_DEBUG_LOCUS) {
if (other->ident == unit && other->tag == offset)
if (other->ident == unit && other->value == offset)
return other->result;
}

Expand Down
17 changes: 17 additions & 0 deletions test/lower/issue972.vhd
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
entity issue972 is
end entity;

architecture test of issue972 is
type t_rec is record
f : integer;
end record;
begin

b: block is
generic ( r : t_rec );
generic map ( r => (f => 5) );
signal s : integer range 1 to r.f;
begin
end block;

end architecture;
35 changes: 35 additions & 0 deletions test/test_lower.c
Original file line number Diff line number Diff line change
Expand Up @@ -6307,6 +6307,40 @@ START_TEST(test_mixed2)
}
END_TEST

START_TEST(test_issue972)
{
input_from_file(TESTDIR "/lower/issue972.vhd");

run_elab();

vcode_unit_t vu = find_unit("WORK.ISSUE972.B");
vcode_select_unit(vu);

EXPECT_BB(0) = {
{ VCODE_OP_PACKAGE_INIT, .name = "STD.STANDARD" },
{ VCODE_OP_INDEX, .name = "R" },
{ VCODE_OP_CONST, .value = 5 },
{ VCODE_OP_CONST_RECORD },
{ VCODE_OP_ADDRESS_OF },
{ VCODE_OP_COPY },
{ VCODE_OP_CONST, .value = 1 },
{ VCODE_OP_RECORD_REF, .field = 0 },
{ VCODE_OP_LOAD_INDIRECT },
{ VCODE_OP_CONST, .value = 0 },
{ VCODE_OP_CONST, .value = 4 },
{ VCODE_OP_CONST, .value = 1 },
{ VCODE_OP_DEBUG_LOCUS },
{ VCODE_OP_RANGE_CHECK },
{ VCODE_OP_CONST, .value = 0 },
{ VCODE_OP_INIT_SIGNAL },
{ VCODE_OP_STORE, .name = "S" },
{ VCODE_OP_RETURN },
};

CHECK_BB(0);
}
END_TEST

Suite *get_lower_tests(void)
{
Suite *s = suite_create("lower");
Expand Down Expand Up @@ -6454,6 +6488,7 @@ Suite *get_lower_tests(void)
tcase_add_test(tc, test_issue859);
tcase_add_test(tc, test_issue934);
tcase_add_test(tc, test_mixed2);
tcase_add_test(tc, test_issue972);
suite_add_tcase(s, tc);

return s;
Expand Down

0 comments on commit 380d593

Please sign in to comment.