Skip to content

Commit

Permalink
Fix crash with call with too many named arguments. Issue #1091 (#1130)
Browse files Browse the repository at this point in the history
  • Loading branch information
NikLeberg authored Jan 12, 2025
1 parent 7efff2a commit 5a8babd
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 1 deletion.
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
## Unreleased changes
- Fixed a crash when a subprogram is called with too many named arguments
(from @NikLeberg) (#1091).

## Version 1.15.0 - 2025-01-11
- `--load` is now a global option and should be placed before the `-r`
Expand Down
11 changes: 10 additions & 1 deletion src/sem.c
Original file line number Diff line number Diff line change
Expand Up @@ -3322,7 +3322,16 @@ static bool sem_check_call_args(tree_t t, tree_t decl, nametab_t *tab)
}
}

if (index == -1 || !tree_has_ref(ref)) {
if (index == -1) {
diag_t *d = diag_new(DIAG_ERROR, tree_loc(param));
diag_printf(d, "subprogram %s has no parameter named %s",
type_pp(tree_type(decl)), istr(id));
diag_hint(d, tree_loc(decl), "subprogram defined here");
diag_emit(d);
return false;
}

if (!tree_has_ref(ref)) {
// Should have generated an error during overload
// resolution
assert(error_count() > 0);
Expand Down
21 changes: 21 additions & 0 deletions test/parse/issue1091b.vhd
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
PACKAGE Vital_Memory IS END Vital_Memory;

PACKAGE BODY Vital_Memory IS
PROCEDURE MemoryTableCorruptMask (
VARIABLE CorruptMask : OUT INTEGER
) IS
BEGIN
END;

PROCEDURE MemoryTableLookUp (
VARIABLE DataCorruptMask : OUT INTEGER;
CONSTANT EnableIndex : IN INTEGER
) IS
BEGIN
MemoryTableCorruptMask (
CorruptMask => DataCorruptMask,
EnableIndex => EnableIndex
);
END;

END PACKAGE BODY Vital_Memory;
20 changes: 20 additions & 0 deletions test/test_parse.c
Original file line number Diff line number Diff line change
Expand Up @@ -7071,6 +7071,25 @@ START_TEST(test_issue1091)
}
END_TEST

START_TEST(test_issue1091b)
{
input_from_file(TESTDIR "/parse/issue1091b.vhd");

const error_t expect[] = {
{ 17, "subprogram MEMORYTABLECORRUPTMASK [INTEGER] "
"has no parameter named ENABLEINDEX" },
{ -1, NULL }
};
expect_errors(expect);

parse_and_check(T_PACKAGE, T_PACK_BODY);

fail_unless(parse() == NULL);

check_expected_errors();
}
END_TEST

START_TEST(test_issue1096)
{
input_from_file(TESTDIR "/parse/issue1096.vhd");
Expand Down Expand Up @@ -7356,6 +7375,7 @@ Suite *get_parse_tests(void)
tcase_add_test(tc_core, test_pkgindecl);
tcase_add_test(tc_core, test_issue1090);
tcase_add_test(tc_core, test_issue1091);
tcase_add_test(tc_core, test_issue1091b);
tcase_add_test(tc_core, test_issue1096);
tcase_add_test(tc_core, test_alias5);
tcase_add_test(tc_core, test_gensub);
Expand Down

0 comments on commit 5a8babd

Please sign in to comment.