Skip to content

Commit

Permalink
Fix crash on duplicated protected body.
Browse files Browse the repository at this point in the history
  • Loading branch information
NikLeberg committed Dec 4, 2024
1 parent 6ecfc8f commit 1429be5
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
5 changes: 5 additions & 0 deletions src/parse.c
Original file line number Diff line number Diff line change
Expand Up @@ -7841,6 +7841,11 @@ static tree_t p_protected_type_body(ident_t id)
if (decl != NULL) {
switch (tree_kind(decl)) {
case T_PROT_BODY: // Duplicate body will trigger an error later
if (!tree_has_primary(decl)) {
assert(error_count() > 0); // Fallout from previous error, ignore
decl = NULL;
break;
}
decl = tree_primary(decl);
// Fall-through
case T_PROT_DECL:
Expand Down
8 changes: 8 additions & 0 deletions test/parse/protected3.vhd
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,11 @@ package fred4 is
impure function hi_there return is_empty; -- error
end protected;
end package fred4;

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

package pkg is
type SharedCounter is protected body -- first definition, but incomplete
type SharedCounter is protected body -- duplicated definition
end protected body;
end package;
5 changes: 4 additions & 1 deletion test/test_parse.c
Original file line number Diff line number Diff line change
Expand Up @@ -6979,11 +6979,14 @@ START_TEST(test_protected3)

const error_t expect[] = {
{ 4, "type mark does not denote a type or a subtype" },
{ 11, "no visible declaration for SHAREDCOUNTER" },
{ 14, "unexpected package while parsing protected type body, "
"expecting protected" },
{ -1, NULL }
};
expect_errors(expect);

parse_and_check(T_PACKAGE);
parse_and_check(T_PACKAGE, T_PACKAGE);

fail_unless(parse() == NULL);

Expand Down

0 comments on commit 1429be5

Please sign in to comment.