Skip to content

Commit

Permalink
Fix crash with invalid aggregate field name
Browse files Browse the repository at this point in the history
  • Loading branch information
NikLeberg committed Jan 6, 2025
1 parent 434f01f commit 64bd8f2
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/names.c
Original file line number Diff line number Diff line change
Expand Up @@ -4433,9 +4433,9 @@ static type_t solve_record_aggregate(nametab_t *tab, tree_t agg, type_t type)
{
push_scope_for_fields(tab, type);
tree_t name = tree_name(a);
solve_types(tab, name, NULL);
type_t ntype = solve_types(tab, name, NULL);
pop_scope(tab);
if (tree_has_ref(name)) {
if (!type_is_none(ntype) && tree_has_ref(name)) {
tree_t field = tree_ref(name);
type_set_add(tab, solve_field_subtype(type, field), field);
if (tree_kind(field) == T_FIELD_DECL) {
Expand Down
17 changes: 17 additions & 0 deletions test/parse/aggregate2.vhd
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package tick is
type t_data_segment is record
end record;

constant C_SEGMENT_RECORDS : t_data_segment := (
data'last => (others => '0')
);
end package;

package brack is
type t_data_segment is record
end record;

constant C_SEGMENT_RECORDS : t_data_segment := (
data[word => (others => '0')
);
end package;
25 changes: 25 additions & 0 deletions test/test_parse.c
Original file line number Diff line number Diff line change
Expand Up @@ -7130,6 +7130,30 @@ START_TEST(test_gensub)
}
END_TEST

START_TEST(test_aggregate2)
{
set_standard(STD_19);

input_from_file(TESTDIR "/parse/aggregate2.vhd");

const error_t expect[] = {
{ 6, "no visible declaration for DATA" },
{ 6, "association choice must be a field name" },
{ 15, "no visible declaration for WORD" },
{ 15, "unexpected => while parsing signature" },
{ 15, "association choice must be a field name" },
{ -1, NULL }
};
expect_errors(expect);

parse_and_check(T_PACKAGE, T_PACKAGE);

fail_unless(parse() == NULL);

check_expected_errors();
}
END_TEST

Suite *get_parse_tests(void)
{
Suite *s = suite_create("parse");
Expand Down Expand Up @@ -7304,6 +7328,7 @@ Suite *get_parse_tests(void)
tcase_add_test(tc_core, test_issue1096);
tcase_add_test(tc_core, test_alias5);
tcase_add_test(tc_core, test_gensub);
tcase_add_test(tc_core, test_aggregate2);
suite_add_tcase(s, tc_core);

return s;
Expand Down

0 comments on commit 64bd8f2

Please sign in to comment.