Skip to content

Commit

Permalink
Missing array bounds check for composite 'VALUE result
Browse files Browse the repository at this point in the history
  • Loading branch information
nickg committed Aug 6, 2023
1 parent 20050fa commit 73e33fe
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/jit/jit-exits.c
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@ void x_length_fail(int64_t left, int64_t right, int32_t dim, tree_t where)
tb_cat(tb, "expected");
break;
case T_TYPE_CONV:
case T_ATTR_REF:
tb_printf(tb, "subtype %s", type_pp(tree_type(where)));
break;
default:
Expand Down
6 changes: 5 additions & 1 deletion src/lower.c
Original file line number Diff line number Diff line change
Expand Up @@ -4696,7 +4696,11 @@ static vcode_reg_t lower_attr_ref(lower_unit_t *lu, tree_t expr)

if (type_is_scalar(name_type))
lower_check_scalar_bounds(lu, reg, name_type, expr, NULL);
// TODO: need array bounds check here
else if (type_is_array(name_type) && lower_const_bounds(name_type)) {
vcode_reg_t locus = lower_debug_locus(expr);
lower_check_array_sizes(lu, name_type, base, VCODE_INVALID_REG,
reg, locus);
}

return reg;
}
Expand Down
19 changes: 19 additions & 0 deletions test/regress/bounds40.vhd
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
entity bounds40 is
end entity;

architecture test of bounds40 is
type t_pair is record
x, y : integer;
end record;

type t_pair_pair is array (1 to 2) of t_pair;
begin

process is
begin
assert t_pair_pair'value("((1,2), (3, 4), (5, 6))")
= ((1,2), (3,4)); -- Error
wait;
end process;

end architecture;
1 change: 1 addition & 0 deletions test/regress/gold/bounds40.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0ms+0: value length 3 does not match subtype T_PAIR_PAIR length 2
1 change: 1 addition & 0 deletions test/regress/testlist.txt
Original file line number Diff line number Diff line change
Expand Up @@ -842,3 +842,4 @@ assert11 normal,2019
assert12 normal
image2 normal,2019
value2 normal,2019
bounds40 fail,2019,gold

0 comments on commit 73e33fe

Please sign in to comment.