Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix crash on package definition in interface decl. #1083

Merged
merged 1 commit into from
Dec 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
format (#1071).
- Added support for package external names (#1072).
- Fixed parser hang for bit string literals (from @NikLeberg).
- 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 @@ -2462,7 +2462,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
17 changes: 9 additions & 8 deletions src/parse.c
Original file line number Diff line number Diff line change
Expand Up @@ -5541,14 +5541,15 @@ static void p_formal_parameter_list(tree_t decl, type_t type)
if (nports == 0)
return; // Was parse error

tree_t p0 = tree_port(decl, 0);
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 = 0; i < nports; i++) {
tree_t p = tree_port(decl, i);
if (i == 0 && tree_has_value(p))
tree_set_flag(decl, TREE_F_CALL_NO_ARGS);
if (tree_has_type(p))
type_add_param(type, tree_type(p));
else
type_add_param(type, type_new(T_NONE)); // Will raise error later
}
}

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 @@ -6991,6 +6991,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 @@ -7159,6 +7181,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
Loading