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 invalid subtype indication. #1082

Merged
merged 1 commit into from
Dec 3, 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
16 changes: 12 additions & 4 deletions src/names.c
Original file line number Diff line number Diff line change
Expand Up @@ -2104,7 +2104,8 @@ void resolve_resolution(nametab_t *tab, tree_t rname, type_t type)
{
// Finding the resolution function is a special case of overload resolution

if (tree_kind(rname) == T_ELEM_RESOLUTION) {
switch (tree_kind(rname)) {
case T_ELEM_RESOLUTION:
if (type_is_record(type))
error_at(tree_loc(rname), "sorry, record element resolution is not "
"supported yet");
Expand All @@ -2118,9 +2119,9 @@ void resolve_resolution(nametab_t *tab, tree_t rname, type_t type)
tree_t a0 = tree_value(tree_assoc(rname, 0));
resolve_resolution(tab, a0, type_elem(type));
}
}
else {
assert(tree_kind(rname) == T_REF);
break;

case T_REF:
tree_set_ref(rname, NULL);

type_set_push(tab);
Expand All @@ -2137,6 +2138,13 @@ void resolve_resolution(nametab_t *tab, tree_t rname, type_t type)
tree_set_ref(rname, finish_overload_resolution(&o));

type_set_pop(tab);
break;

default:
error_at(tree_loc(rname), "not a valid resolution function for type %s",
type_pp(type));
tree_set_type(rname, type_new(T_NONE));
break;
}
}

Expand Down
6 changes: 5 additions & 1 deletion src/sem.c
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,11 @@ static bool sem_check_resolution(type_t type, tree_t res)
}
}

assert(tree_kind(res) == T_REF);
if (tree_kind(res) != T_REF) {
// Should have been caught during name resolution
assert(error_count() > 0);
return false;
}

if (!tree_has_ref(res))
return false;
Expand Down
21 changes: 17 additions & 4 deletions test/parse/issue1038.vhd
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,14 @@ package body foo_pkg is
end package body bar_pkg;
end package body foo_pkg;

--------------------------------------------------------------------------------

package foo is
alias TO_OCTAL_STRING is ns;
end package foo;

--------------------------------------------------------------------------------

ENTITY psl_func_in_primary IS
END psl_func_in_primary;

Expand All @@ -26,12 +30,21 @@ ARCHITECTURE arch OF psl_func_in_primary IS
BEGIN
END ARCHITECTURE arch;

--------------------------------------------------------------------------------

package long_pkg is
end package;

package body long_pkg is
procedure bar is
begin
report "" ; natural ;
end procedure;
procedure bar is
begin
report "" ; natural ;
end procedure;
end package body;

--------------------------------------------------------------------------------

package resolution_fn_err is
constant c : positive;
subtype sub is c'active positive;
end package;
7 changes: 4 additions & 3 deletions test/test_parse.c
Original file line number Diff line number Diff line change
Expand Up @@ -6920,15 +6920,16 @@ START_TEST(test_issue1038)
input_from_file(TESTDIR "/parse/issue1038.vhd");

const error_t expect[] = {
{ 22, "unexpected next while parsing primary, expecting one of ??, (, "
{ 26, "unexpected next while parsing primary, expecting one of ??, (, "
"integer, real, null, identifier, string, bit string or new" },
{ 35, "no visible subprogram declaration for NATURAL" },
{ 41, "no visible subprogram declaration for NATURAL" },
{ 49, "not a valid resolution function for type POSITIVE" },
{ -1, NULL }
};
expect_errors(expect);

parse_and_check(T_PACKAGE, T_PACK_BODY, T_PACKAGE, T_ENTITY, T_ARCH,
T_PACKAGE, T_PACK_BODY);
T_PACKAGE, T_PACK_BODY, T_PACKAGE);

fail_unless(parse() == NULL);

Expand Down
Loading