From aa11a9e0c178554220efd891a6e731932e89848a Mon Sep 17 00:00:00 2001 From: Nick Gasson Date: Sun, 29 Sep 2024 11:24:03 +0100 Subject: [PATCH] Fix error when work library has same name as entity. Fixes #991 --- NEWS.md | 2 ++ src/parse.c | 36 ++++++++++-------------------------- test/parse/issue991.vhd | 13 +++++++++++++ test/test_parse.c | 13 +++++++++++++ 4 files changed, 38 insertions(+), 26 deletions(-) create mode 100644 test/parse/issue991.vhd diff --git a/NEWS.md b/NEWS.md index 205b05107..d278aeb16 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,4 +1,6 @@ ## Unreleased changes +- Fixed an error when using the `work` library alias and the working + library has the same name as design unit being analysed (#991). ## Version 1.14.0 - 2024-09-22 - Waiting on implicit `'stable` and `'quiet` signals now works diff --git a/src/parse.c b/src/parse.c index 8ad08b3e1..84f9b6f59 100644 --- a/src/parse.c +++ b/src/parse.c @@ -1567,27 +1567,6 @@ static tree_t ensure_labelled(tree_t t, ident_t label) return t; } -static tree_t external_reference(tree_t t) -{ - switch (tree_kind(t)) { - case T_ENTITY: - case T_LIBRARY: - case T_ARCH: - case T_PACKAGE: - case T_PACK_INST: - case T_CONFIGURATION: - { - tree_t ref = tree_new(T_REF); - tree_set_loc(ref, CURRENT_LOC); - tree_set_ident(ref, tree_ident(t)); - tree_set_ref(ref, t); - return ref; - } - default: - return t; - } -} - static tree_t select_decl(tree_t prefix, ident_t suffix, name_mask_t *mask) { ident_t qual = ident_prefix(tree_ident(prefix), suffix, '.'); @@ -3488,8 +3467,6 @@ static tree_t p_attribute_name(tree_t prefix) type = tree_type(prefix); } - prefix = external_reference(prefix); - tree_t t = tree_new(T_ATTR_REF); tree_set_name(t, prefix); @@ -3570,7 +3547,7 @@ static tree_t p_selected_name(tree_t prefix, name_mask_t *mask) tree_t decl = tree_ref(prefix); const tree_kind_t kind = tree_kind(decl); if (kind == T_LIBRARY) { - ident_t unit_name = ident_prefix(tree_ident(decl), suffix, '.'); + ident_t unit_name = ident_prefix(tree_ident(prefix), suffix, '.'); tree_t unit = resolve_name(nametab, CURRENT_LOC, unit_name); if (unit == NULL) { tree_t dummy = tree_new(T_REF); @@ -3579,8 +3556,15 @@ static tree_t p_selected_name(tree_t prefix, name_mask_t *mask) *mask |= N_ERROR; return dummy; } - else - return external_reference(unit); + else { + assert(is_design_unit(unit)); + + tree_t ref = tree_new(T_REF); + tree_set_loc(ref, CURRENT_LOC); + tree_set_ident(ref, unit_name); + tree_set_ref(ref, unit); + return ref; + } } else if (kind == T_GENERIC_DECL && tree_class(decl) == C_PACKAGE) return select_decl(tree_value(decl), suffix, mask); diff --git a/test/parse/issue991.vhd b/test/parse/issue991.vhd new file mode 100644 index 000000000..c76675245 --- /dev/null +++ b/test/parse/issue991.vhd @@ -0,0 +1,13 @@ +package pack is + type t_enum is (a, b, c); +end package; + +------------------------------------------------------------------------------- + +entity issue991 is +end entity; + +architecture test of issue991 is + constant c : work.pack.t_enum := work.pack.a; -- OK +begin +end architecture; diff --git a/test/test_parse.c b/test/test_parse.c index 473d235e9..98e5e51e7 100644 --- a/test/test_parse.c +++ b/test/test_parse.c @@ -6897,6 +6897,18 @@ START_TEST(test_issue977) } END_TEST +START_TEST(test_issue991) +{ + input_from_file(TESTDIR "/parse/issue991.vhd"); + + parse_and_check(T_PACKAGE, T_ENTITY, T_ARCH); + + fail_unless(parse() == NULL); + + fail_if_errors(); +} +END_TEST + Suite *get_parse_tests(void) { Suite *s = suite_create("parse"); @@ -7060,6 +7072,7 @@ Suite *get_parse_tests(void) tcase_add_test(tc_core, test_issue956); tcase_add_test(tc_core, test_issue961); tcase_add_test(tc_core, test_issue977); + tcase_add_test(tc_core, test_issue991); suite_add_tcase(s, tc_core); return s;