Skip to content

Commit

Permalink
Correct type check in lower_port_ref
Browse files Browse the repository at this point in the history
  • Loading branch information
nickg committed Dec 7, 2023
1 parent 6bb7e5b commit dc111cd
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/lower.c
Original file line number Diff line number Diff line change
Expand Up @@ -2874,14 +2874,14 @@ static vcode_reg_t lower_signal_ref(lower_unit_t *lu, tree_t decl)
ptr_reg = emit_link_var(pkg_reg, tree_ident(decl), vtype);
}
}
else if (hops == 0 && vtype_kind(vcode_var_type(var)) != VCODE_TYPE_RECORD)
else if (hops == 0 && vtype_is_scalar(vcode_var_type(var)))
return emit_load(var);
else if (hops == 0)
ptr_reg = emit_index(var, VCODE_INVALID_REG);
else
ptr_reg = emit_var_upref(hops, var);

if (vtype_kind(vtype_pointed(vcode_reg_type(ptr_reg))) == VCODE_TYPE_RECORD)
if (!vtype_is_scalar(vtype_pointed(vcode_reg_type(ptr_reg))))
return ptr_reg;

return emit_load_indirect(ptr_reg);
Expand All @@ -2896,7 +2896,7 @@ static vcode_reg_t lower_port_ref(lower_unit_t *lu, tree_t decl)
fatal_trace("missing variable for port %s", istr(tree_ident(decl)));
}

if (hops == 0 && vtype_kind(vcode_var_type(var)) != VCODE_TYPE_RECORD)
if (hops == 0 && vtype_is_scalar(vcode_var_type(var)))
return emit_load(var);

vcode_reg_t ptr_reg;
Expand All @@ -2905,7 +2905,7 @@ static vcode_reg_t lower_port_ref(lower_unit_t *lu, tree_t decl)
else
ptr_reg = emit_var_upref(hops, var);

if (vtype_kind(vtype_pointed(vcode_reg_type(ptr_reg))) == VCODE_TYPE_RECORD)
if (!vtype_is_scalar(vtype_pointed(vcode_reg_type(ptr_reg))))
return ptr_reg;

return emit_load_indirect(ptr_reg);
Expand Down
21 changes: 21 additions & 0 deletions test/lower/directmap4.vhd
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
entity directmap4 is
end entity;

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

type t_rec_array is array (natural range <>) of t_rec;

signal x : t_rec_array(1 to 1);
begin

b: block is
port ( p : out t_rec_array(1 to 1) );
port map ( x );
begin
p <= (1 => (f => 1));
end block;

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

START_TEST(test_directmap4)
{
input_from_file(TESTDIR "/lower/directmap4.vhd");

run_elab();

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

EXPECT_BB(1) = {
{ VCODE_OP_LOAD, .name = "i1" },
{ VCODE_OP_ARRAY_REF },
{ VCODE_OP_ARRAY_REF },
{ VCODE_OP_RECORD_REF },
{ VCODE_OP_RECORD_REF },
{ VCODE_OP_LOAD_INDIRECT },
{ VCODE_OP_CONST, .value = 1 },
{ VCODE_OP_MAP_CONST },
{ VCODE_OP_ADD },
{ VCODE_OP_STORE, .name = "i1" },
{ VCODE_OP_CMP, .cmp = VCODE_CMP_EQ },
{ VCODE_OP_COND, .target = 2, .target_else = 1 },
};

CHECK_BB(1);
}
END_TEST

Suite *get_lower_tests(void)
{
Suite *s = suite_create("lower");
Expand Down Expand Up @@ -5832,6 +5860,7 @@ Suite *get_lower_tests(void)
tcase_add_test(tc, test_issue791);
tcase_add_test(tc, test_osvvm3);
tcase_add_test(tc, test_bounds2);
tcase_add_test(tc, test_directmap4);
suite_add_tcase(s, tc);

return s;
Expand Down

0 comments on commit dc111cd

Please sign in to comment.