From 498ae014c4b9a9dbf911af662121ed47ed1703ae Mon Sep 17 00:00:00 2001 From: Nick Gasson Date: Fri, 23 Aug 2024 21:42:16 +0100 Subject: [PATCH] Use clause with .all suffix should not make package name visible --- NEWS.md | 2 ++ src/names.c | 56 +++++++++++++++++-------------------- test/parse/visibility12.vhd | 30 ++++++++++++++++++++ test/sem/duplicate.vhd | 4 +-- test/sem/issue311.vhd | 5 ++-- test/sem/scope.vhd | 2 +- test/test_parse.c | 23 +++++++++++++++ test/test_sem.c | 6 ++-- 8 files changed, 89 insertions(+), 39 deletions(-) create mode 100644 test/parse/visibility12.vhd diff --git a/NEWS.md b/NEWS.md index cf098230a..7cb37656b 100644 --- a/NEWS.md +++ b/NEWS.md @@ -24,6 +24,8 @@ package (#946). - Fixed random crashes when the simulation heap size is eight gigabytes or larger (#949). +- `use lib.pack.all` no longer makes the bare package name `pack` + potentially visible. ## Version 1.13.2 - 2024-08-11 - Fixed an incorrect bounds check error when a constant declaration has diff --git a/src/names.c b/src/names.c index 93bf53ac7..a5e992130 100644 --- a/src/names.c +++ b/src/names.c @@ -1052,12 +1052,6 @@ static void make_potentially_visible(scope_t *s, ident_t id, tree_t d) make_visible(s, id, d, POTENTIAL, s); } -static ident_t unit_bare_name(tree_t unit) -{ - ident_t unit_name = tree_ident(unit); - return ident_rfrom(unit_name, '.') ?: unit_name; -} - static scope_t *scope_for_type(nametab_t *tab, type_t type) { assert(type_is_protected(type)); @@ -1176,10 +1170,6 @@ static scope_t *private_scope_for(nametab_t *tab, tree_t unit) default: break; } - - ident_t bare_name = unit_bare_name(unit); - if (symbol_for(s, bare_name) == NULL) - make_visible_fast(s, bare_name, unit); } hash_put(cache, key, s); @@ -1787,24 +1777,32 @@ tree_t resolve_name(nametab_t *tab, const loc_t *loc, ident_t name) ident_t prefix = ident_runtil(name, '.'); const symbol_t *psym = prefix ? iterate_symbol_for(tab, prefix) : NULL; - if (psym != NULL && psym->ndecls == 1) { - if (psym->decls[0].kind == T_LIBRARY) { - lib_t lib = lib_require(psym->name); - if (lib_had_errors(lib, name)) { - diag_printf(d, "design unit depends on %s which was analysed" - " with errors", istr(name)); - tab->top_scope->suppress = true; + if (psym != NULL) { + for (int i = 0; i < psym->ndecls; i++) { + const decl_t *dd = get_decl(psym, i); + if (dd->visibility == HIDDEN) + diag_hint(d, tree_loc(dd->tree), "%s %s is hidden", + class_str(class_of(dd->tree)), istr(psym->name)); + else if (dd->kind == T_LIBRARY) { + lib_t lib = lib_require(psym->name); + if (lib_had_errors(lib, name)) { + diag_printf(d, "design unit depends on %s which was " + "analysed with errors", istr(name)); + tab->top_scope->suppress = true; + } + else + diag_printf(d, "design unit %s not found in library %s", + istr(ident_rfrom(name, '.')), + istr(psym->name)); + break; + } + else { + diag_printf(d, "name %s not found in %s %s", + istr(ident_rfrom(name, '.')), + class_str(class_of(dd->tree)), istr(psym->name)); + break; } - else - diag_printf(d, "design unit %s not found in library %s", - istr(ident_rfrom(name, '.')), istr(psym->name)); } - else - diag_printf(d, "name %s not found in %s %s", - istr(ident_rfrom(name, '.')), - (is_design_unit(psym->decls[0].tree) - ? "design unit" : "object"), - istr(psym->name)); } else diag_printf(d, "no visible declaration for %s", istr(name)); @@ -2097,7 +2095,7 @@ void resolve_resolution(nametab_t *tab, tree_t rname, type_t type) tree_t find_std(nametab_t *tab) { if (tab->std == NULL) { - tab->std = resolve_name(tab, NULL, ident_new("STANDARD")); + tab->std = resolve_name(tab, NULL, ident_new("STD.STANDARD")); if (tab->std == NULL) fatal_trace("cannot continue without STD.STANDARD"); } @@ -2167,7 +2165,7 @@ void insert_names_from_use(nametab_t *tab, tree_t use) const symbol_t *sym = symbol_for(s, what); if (sym == NULL) { error_at(tree_loc(use), "name %s not found in %s %s", - istr(what), is_design_unit(unit) ? "design unit" : "object", + istr(what), class_str(class_of(unit)), istr(tree_ident(unit))); return; } @@ -2194,8 +2192,6 @@ void insert_names_from_use(nametab_t *tab, tree_t use) } } } - - merge_symbol(tab->top_scope, symbol_for(s, unit_bare_name(unit))); } } diff --git a/test/parse/visibility12.vhd b/test/parse/visibility12.vhd new file mode 100644 index 000000000..fb0e1f43b --- /dev/null +++ b/test/parse/visibility12.vhd @@ -0,0 +1,30 @@ +-- work library is mylib +package mylib is + constant C_CONSTANT : integer := 2; +end package; + +entity cntr is + port ( x : in integer ); +end entity; + +library mylib; +use mylib.mylib.all; + +entity e1 is +end entity; + +architecture a1 of e1 is +begin + u: entity mylib.cntr port map ( C_CONSTANT); -- OK +end architecture; + +library mylib; +use mylib.mylib; + +entity e2 is +end entity; + +architecture a2 of e2 is +begin + u: entity mylib.cntr port map ( mylib.C_CONSTANT); -- Error +end architecture; diff --git a/test/sem/duplicate.vhd b/test/sem/duplicate.vhd index 293370683..5711f04e0 100644 --- a/test/sem/duplicate.vhd +++ b/test/sem/duplicate.vhd @@ -24,9 +24,9 @@ begin process is begin assert func(2) = 3; -- OK - assert pack.func(2) = 3; -- OK + assert work.pack.func(2) = 3; -- OK proc(2); -- OK - pack.proc(2); -- OK + work.pack.proc(2); -- OK wait; end process; diff --git a/test/sem/issue311.vhd b/test/sem/issue311.vhd index ad88c3542..f03b0517c 100644 --- a/test/sem/issue311.vhd +++ b/test/sem/issue311.vhd @@ -20,8 +20,8 @@ package p2 is type EVENT_TYPE is (EVENT_1, EVENT_2); end package; -use work.p1.all; -use work.p2.all; +use work.p1; +use work.p2; entity e is end entity; @@ -29,7 +29,6 @@ end entity; architecture a of e is constant event1 : P1.EVENT_TYPE := P1.EVENT_1; -- OK constant event2 : P2.EVENT_TYPE := P2.EVENT_1; -- OK - constant event3 : EVENT_TYPE := EVENT_1; -- Error constant event4 : P1.EVENT_TYPE := P2.EVENT_1; -- Error begin diff --git a/test/sem/scope.vhd b/test/sem/scope.vhd index 7abc91c70..0c090c275 100644 --- a/test/sem/scope.vhd +++ b/test/sem/scope.vhd @@ -208,7 +208,7 @@ begin begin assert 1 and 2; -- OK assert work.pack5."and"(1, 2); -- OK - assert pack5."and"(1, 2); -- OK + assert pack5."and"(1, 2); -- Error end process; end architecture; diff --git a/test/test_parse.c b/test/test_parse.c index d5b3763f4..967a90a3d 100644 --- a/test/test_parse.c +++ b/test/test_parse.c @@ -6790,6 +6790,28 @@ START_TEST(test_lcs2016_i03) } END_TEST +START_TEST(test_visibility12) +{ + input_from_file(TESTDIR "/parse/visibility12.vhd"); + + const error_t expect[] = { + { 29, "name CNTR not found in package MYLIB" }, + { 0, "library MYLIB is hidden" }, + { -1, NULL } + }; + expect_errors(expect); + + lib_t mylib = lib_tmp("mylib"); + lib_set_work(mylib); + + parse_and_check(T_PACKAGE, T_ENTITY, T_ENTITY, T_ARCH, T_ENTITY, T_ARCH); + + fail_unless(parse() == NULL); + + check_expected_errors(); +} +END_TEST + Suite *get_parse_tests(void) { Suite *s = suite_create("parse"); @@ -6948,6 +6970,7 @@ Suite *get_parse_tests(void) tcase_add_test(tc_core, test_vunit10); tcase_add_test(tc_core, test_issue942); tcase_add_test(tc_core, test_lcs2016_i03); + tcase_add_test(tc_core, test_visibility12); suite_add_tcase(s, tc_core); return s; diff --git a/test/test_sem.c b/test/test_sem.c index ef49acd3f..a8b370249 100644 --- a/test/test_sem.c +++ b/test/test_sem.c @@ -176,8 +176,9 @@ START_TEST(test_scope) { 114, "no visible declaration for MY_INT1" }, { 137, "no visible declaration for E1" }, { 160, "no visible subprogram declaration for FUNC2" }, - { 167, "name NOT_HERE not found in design unit WORK.PACK5" }, + { 167, "name NOT_HERE not found in package WORK.PACK5" }, { 189, "no visible declaration for MY_INT1" }, + { 211, "no visible declaration for PACK5" }, { 236, "no visible declaration for FOO" }, { 302, "declaration of I hides an earlier declaration with the same " }, { 306, "name X not found in L1" }, @@ -1990,8 +1991,7 @@ START_TEST(test_issue311) input_from_file(TESTDIR "/sem/issue311.vhd"); const error_t expect[] = { - { 32, "multiple conflicting visible declarations of EVENT_TYPE" }, - { 33, "type of initial value WORK.P2.EVENT_TYPE does not match" }, + { 32, "type of initial value WORK.P2.EVENT_TYPE does not match" }, { -1, NULL } }; expect_errors(expect);