Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Forbid implicit declarations #217

Open
corco opened this issue Feb 23, 2020 · 3 comments · May be fixed by #244
Open

Forbid implicit declarations #217

corco opened this issue Feb 23, 2020 · 3 comments · May be fixed by #244
Labels
style-linter Verilog style-linter issues

Comments

@corco
Copy link
Collaborator

corco commented Feb 23, 2020

SystemVerilog allow implicit net declaration (language specification section 6.10). While useful for netlists, in traditional code it allows bugs to go undetected:

  • A typo can declare an extra net instead of using intended one
  • Forgetting to declare a net will implicitly declare it as 1 bit net, which may not be the desired type.

In both cases, the resulting code is legal and may be partly functional, making it hard to detect the issue.

I would like to see implicit net detected and reported in the linter.

@fangism
Copy link
Collaborator

fangism commented Feb 24, 2020

Couldn't agree more, would love to see this. (Have a horror story about this kind of issue...)
Even though this borders on semantic/symbolic linting, this (use/def checking) is achievable with the style linter. None of the current style lint rules do any symbol tracking/resolution yet, that would be the first step.

@fangism fangism added the style-linter Verilog style-linter issues label Feb 24, 2020
@fangism
Copy link
Collaborator

fangism commented Feb 24, 2020

b/138353038

@rdburns
Copy link

rdburns commented Dec 30, 2020

There is a somewhat easy way to deal with this.

At the top of a module file, you should set

`default_nettype none

This will cause an undeclared net to trigger a real error in whatever tool the user is using.

A caveat: once you do this, any i/o wire have to be declared explicitly (many people just write input somesig, and that takes advantage of the default nettype being wire).

A 2nd caveat: The default nettype persists across files after a compiler reads it, so you should to set default_nettype back to wire at the end of the file, as a lot of code assumes it.

`default_nettype wire

Now all that said, I would love there to be a lint rule to check if default_nettype is set to none at the start of a file and wire at the end, and that would be a lot easier to implement than trying to verify nets are declared.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
style-linter Verilog style-linter issues
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants