diff --git a/src/lower.c b/src/lower.c index be6db65fa..efe2a64ba 100644 --- a/src/lower.c +++ b/src/lower.c @@ -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); @@ -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; @@ -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); diff --git a/test/lower/directmap4.vhd b/test/lower/directmap4.vhd new file mode 100644 index 000000000..f99c0e682 --- /dev/null +++ b/test/lower/directmap4.vhd @@ -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; diff --git a/test/test_lower.c b/test/test_lower.c index 01e1c466e..70a00628d 100644 --- a/test/test_lower.c +++ b/test/test_lower.c @@ -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"); @@ -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;