Don't allow package scoped identifiers to cross the package boundary

Package scoped identifiers should only be able to access identifiers that
are declared in the package, but not identifiers that are visible in the
package, but declared outside of it.

```
int x;
package P;
  int y;
endpackage

module test;
  initial begin
    $display(P::x); // Should fail
    $display(P::y); // OK
  end
endmodule
```

Make sure that the symbol search will not attempt to cross the package
boundary during identifier lookup.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
This commit is contained in:
Lars-Peter Clausen 2022-12-28 18:49:23 -08:00
parent e24aa18a80
commit 43fe03dc75
2 changed files with 8 additions and 5 deletions

View File

@ -107,7 +107,7 @@ static inline bool test_function_return_value(const symbol_search_results&search
extern bool symbol_search(const LineInfo*li, Design*des, NetScope*scope,
pform_name_t path, struct symbol_search_results*res,
NetScope*start_scope = 0);
NetScope*start_scope = nullptr, bool prefix_scope = false);
extern bool symbol_search(const LineInfo *li, Design *des, NetScope *scope,
const pform_scoped_name_t &path,

View File

@ -39,10 +39,9 @@ using namespace std;
bool symbol_search(const LineInfo*li, Design*des, NetScope*scope,
pform_name_t path, struct symbol_search_results*res,
NetScope*start_scope)
NetScope*start_scope, bool prefix_scope)
{
assert(scope);
bool prefix_scope = false;
if (debug_elaborate) {
cerr << li->get_fileline() << ": symbol_search: "
@ -69,7 +68,8 @@ bool symbol_search(const LineInfo*li, Design*des, NetScope*scope,
// recursively. Ideally, the result is a scope that we search
// for the tail key, but there are other special cases as well.
if (! path.empty()) {
bool flag = symbol_search(li, des, scope, path, res, start_scope);
bool flag = symbol_search(li, des, scope, path, res, start_scope,
prefix_scope);
if (! flag)
return false;
@ -314,14 +314,17 @@ bool symbol_search(const LineInfo *li, Design *des, NetScope *scope,
struct symbol_search_results *res)
{
NetScope *search_scope = scope;
bool prefix_scope = false;
if (path.package) {
search_scope = des->find_package(path.package->pscope_name());
if (!search_scope)
return false;
prefix_scope = true;
}
return symbol_search(li, des, search_scope, path.name, res, nullptr);
return symbol_search(li, des, search_scope, path.name, res, search_scope,
prefix_scope);
}
/*