Skip to content

Commit

Permalink
Use clause with .all suffix should not make package name visible
Browse files Browse the repository at this point in the history
  • Loading branch information
nickg committed Aug 23, 2024
1 parent e2cc2fe commit 498ae01
Show file tree
Hide file tree
Showing 8 changed files with 89 additions and 39 deletions.
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
56 changes: 26 additions & 30 deletions src/names.c
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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));
Expand Down Expand Up @@ -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");
}
Expand Down Expand Up @@ -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;
}
Expand All @@ -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)));
}
}

Expand Down
30 changes: 30 additions & 0 deletions test/parse/visibility12.vhd
Original file line number Diff line number Diff line change
@@ -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;
4 changes: 2 additions & 2 deletions test/sem/duplicate.vhd
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
5 changes: 2 additions & 3 deletions test/sem/issue311.vhd
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,15 @@ 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;

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

Expand Down
2 changes: 1 addition & 1 deletion test/sem/scope.vhd
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
23 changes: 23 additions & 0 deletions test/test_parse.c
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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;
Expand Down
6 changes: 3 additions & 3 deletions test/test_sem.c
Original file line number Diff line number Diff line change
Expand Up @@ -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" },
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 498ae01

Please sign in to comment.