Skip to content

Commit

Permalink
Fix crash on invalid subtype indication. Issue nickg#1038
Browse files Browse the repository at this point in the history
  • Loading branch information
NikLeberg committed Nov 26, 2024
1 parent 0733039 commit 75adf4f
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 4 deletions.
3 changes: 2 additions & 1 deletion src/parse.c
Original file line number Diff line number Diff line change
Expand Up @@ -4219,7 +4219,8 @@ static type_t p_subtype_indication(void)
rname = p_resolution_indication();
else {
tree_t name = p_name(N_TYPE);
if (peek() == tID)
tree_kind_t kind = tree_kind(name);
if (peek() == tID && (kind == T_REF || kind == T_ELEM_RESOLUTION))
rname = name;
else
type = name_to_type_mark(name);
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" },
{ 53, "unexpected identifier while parsing subtype declaration, "
"expecting ;" },
{ 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 75adf4f

Please sign in to comment.