Skip to content

Commit

Permalink
Fix crash on package definition in interface decl.
Browse files Browse the repository at this point in the history
  • Loading branch information
NikLeberg committed Dec 3, 2024
1 parent 5c6ec2e commit 14e19ec
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 4 deletions.
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
- Nested arrays more than two levels deep can now be dumped in FST
format (#1071).
- Added support for package external names (#1072).
- Fixed a crash on an illegal package definition inside an interface.
- Several other minor bugs were resolved (#1038, #1057, #1067).

## Version 1.14.2 - 2024-11-23
Expand Down
3 changes: 2 additions & 1 deletion src/names.c
Original file line number Diff line number Diff line change
Expand Up @@ -2454,7 +2454,8 @@ void mangle_func(nametab_t *tab, tree_t decl)
tree_t p = tree_port(decl, i);
if (tree_class(p) == C_SIGNAL)
tb_append(buf, 's');
mangle_one_type(buf, tree_type(p));
if (tree_has_type(p))
mangle_one_type(buf, tree_type(p));
}

if (nports > 0 || is_func)
Expand Down
10 changes: 7 additions & 3 deletions src/parse.c
Original file line number Diff line number Diff line change
Expand Up @@ -5536,13 +5536,17 @@ static void p_formal_parameter_list(tree_t decl, type_t type)
return; // Was parse error

tree_t p0 = tree_port(decl, 0);
type_add_param(type, tree_type(p0));
if (tree_has_type(p0))
type_add_param(type, tree_type(p0));

if (tree_has_value(p0))
tree_set_flag(decl, TREE_F_CALL_NO_ARGS);

for (int i = 1; i < nports; i++)
type_add_param(type, tree_type(tree_port(decl, i)));
for (int i = 1; i < nports; i++) {
tree_t p = tree_port(decl, i);
if (tree_has_type(p))
type_add_param(type, tree_type(p));
}
}

static tree_t p_interface_function_specification(void)
Expand Down
9 changes: 9 additions & 0 deletions test/parse/pkgindecl.vhd
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
entity pkg_in_decl is begin end entity;

architecture arch of pkg_in_decl is
function test(
package inner_pkg is end package; -- error
) is begin
end function;
begin
end architecture;
23 changes: 23 additions & 0 deletions test/test_parse.c
Original file line number Diff line number Diff line change
Expand Up @@ -6981,6 +6981,28 @@ START_TEST(test_protected3)
}
END_TEST

START_TEST(test_pkgindecl)
{
opt_set_int(OPT_RELAXED, 1);
set_standard(STD_08);

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

const error_t expect[] = {
{ 5, "unexpected end while parsing interface package declaration, "
"expecting new"},
{ -1, NULL }
};
expect_errors(expect);

parse_and_check(T_ENTITY, T_ARCH);

fail_unless(parse() == NULL);

check_expected_errors();
}
END_TEST

Suite *get_parse_tests(void)
{
Suite *s = suite_create("parse");
Expand Down Expand Up @@ -7149,6 +7171,7 @@ Suite *get_parse_tests(void)
tcase_add_test(tc_core, test_issue1055);
tcase_add_test(tc_core, test_hang);
tcase_add_test(tc_core, test_protected3);
tcase_add_test(tc_core, test_pkgindecl);
suite_add_tcase(s, tc_core);

return s;
Expand Down

0 comments on commit 14e19ec

Please sign in to comment.