Skip to content

Commit

Permalink
Fix crash on invalid subtype indication. Issue #1038
Browse files Browse the repository at this point in the history
  • Loading branch information
NikLeberg committed Nov 28, 2024
1 parent 2d8f452 commit 31ce445
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 8 deletions.
13 changes: 8 additions & 5 deletions src/parse.c
Original file line number Diff line number Diff line change
Expand Up @@ -4226,13 +4226,16 @@ static type_t p_subtype_indication(void)
}

if (rname != NULL) {
type = type_new(T_SUBTYPE);
made_subtype = true;
tree_kind_t kind = tree_kind(rname);
if (kind == T_REF || kind == T_ELEM_RESOLUTION) {
type = type_new(T_SUBTYPE);
made_subtype = true;

type_set_resolution(type, rname);
type_set_base(type, p_type_mark());
type_set_resolution(type, rname);
type_set_base(type, p_type_mark());

resolve_resolution(nametab, rname, type);
resolve_resolution(nametab, rname, type);
}
}

if (type == NULL)
Expand Down
17 changes: 17 additions & 0 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,6 +30,8 @@ ARCHITECTURE arch OF psl_func_in_primary IS
BEGIN
END ARCHITECTURE arch;

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

package long_pkg is
end package;

Expand All @@ -35,3 +41,14 @@ package body long_pkg is
report "" ; natural ;
end procedure;
end package body;

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

package invalid_pkg is
impure function foo
end package;

architecture arch of subtype_err is
begin
subtype sub is up'att another;
end architecture;
12 changes: 9 additions & 3 deletions test/test_parse.c
Original file line number Diff line number Diff line change
Expand Up @@ -6920,15 +6920,21 @@ 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, "unexpected end while parsing subprogram specification, "
"expecting one of generic, (, parameter or return" },
{ 54, "unexpected architecture while parsing package declaration, "
"expecting one of package or ;" },
{ 54, "unexpected ; while parsing library unit, expecting one of "
"entity, configuration, architecture, package or context" },
{ -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

0 comments on commit 31ce445

Please sign in to comment.