Skip to content

Commit

Permalink
Fix bug in handling of enumeration literal alias with signature
Browse files Browse the repository at this point in the history
  • Loading branch information
nickg committed Feb 27, 2023
1 parent c9e1059 commit 1c81bcc
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 12 deletions.
11 changes: 1 addition & 10 deletions src/common.c
Original file line number Diff line number Diff line change
Expand Up @@ -503,17 +503,8 @@ class_t class_of(tree_t t)
case T_ARRAY_SLICE:
case T_RECORD_REF:
case T_ALL:
return class_of(tree_value(t));
case T_ALIAS:
if (tree_has_type(t)) {
switch (type_kind(tree_type(t))) {
case T_FUNC: return C_FUNCTION;
case T_PROC: return C_PROCEDURE;
default: return class_of(tree_value(t));
}
}
else
return class_of(tree_value(t));
return class_of(tree_value(t));
case T_PACKAGE:
case T_PACK_BODY:
case T_PACK_INST:
Expand Down
11 changes: 9 additions & 2 deletions src/names.c
Original file line number Diff line number Diff line change
Expand Up @@ -3232,8 +3232,15 @@ static type_t solve_ref(nametab_t *tab, tree_t ref)
return type;
}

if (tree_kind(decl) == T_ALIAS && !tree_has_type(decl))
type = tree_type(tree_value(decl));
if (tree_kind(decl) == T_ALIAS) {
// An alias declaration for an enumeration literal may contain a
// signature so make sure it doesn't look like a subprogram
tree_t aliased = tree_value(decl);
if (!tree_has_type(decl) || class_of(aliased) == C_LITERAL)
type = tree_type(aliased);
else
type = tree_type(decl);
}
else
type = tree_type(decl);

Expand Down
29 changes: 29 additions & 0 deletions test/parse/alias3.vhd
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package pack1 is
type t is (foo, bar);
end package;

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

use work.pack1.all;

package pack2 is
alias foo is work.pack1.foo [return t];
procedure foo;
procedure bar(arg : t);
end package;

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

entity e is
end entity;

use work.pack2.all;

architecture test of e is
begin
p1: process is
begin
bar(foo); -- OK
wait;
end process;
end architecture;
30 changes: 30 additions & 0 deletions test/test_parse.c
Original file line number Diff line number Diff line change
Expand Up @@ -5262,6 +5262,35 @@ START_TEST(test_vunit9)
}
END_TEST

START_TEST(test_alias3)
{
input_from_file(TESTDIR "/parse/alias3.vhd");

tree_t p1 = parse();
fail_if(p1 == NULL);
fail_unless(tree_kind(p1) == T_PACKAGE);
lib_put(lib_work(), p1);

tree_t p2 = parse();
fail_if(p2 == NULL);
fail_unless(tree_kind(p2) == T_PACKAGE);
lib_put(lib_work(), p2);

tree_t e = parse();
fail_if(e == NULL);
fail_unless(tree_kind(e) == T_ENTITY);
lib_put(lib_work(), e);

tree_t a = parse();
fail_if(a == NULL);
fail_unless(tree_kind(a) == T_ARCH);

fail_unless(parse() == NULL);

fail_if_errors();
}
END_TEST

Suite *get_parse_tests(void)
{
Suite *s = suite_create("parse");
Expand Down Expand Up @@ -5367,6 +5396,7 @@ Suite *get_parse_tests(void)
tcase_add_test(tc_core, test_issue541);
tcase_add_test(tc_core, test_issue604);
tcase_add_test(tc_core, test_vunit9);
tcase_add_test(tc_core, test_alias3);
suite_add_tcase(s, tc_core);

return s;
Expand Down

0 comments on commit 1c81bcc

Please sign in to comment.