-
Notifications
You must be signed in to change notification settings - Fork 119
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
Warnings to capture binary operations width mismatch #918
Comments
Take a look at -Wextra, -Wwidth-trunc, -Wwidth-expand, -Wport-width-expand, -Wport-width-trunc
|
It is true that there is no specific warning for binary operator width mismatch, only warnings about conversions on assignments. More generally this relates to the weird Verilog "feature" of propagating the type of the lhs back down to the rhs, through binary operators. slang doesn't currently warn for propagated type conversions, because I'm worried there will be many such warnings. Even the "canonical" example of the bit width feature below would warn for the 17-bit add; maybe you want that and maybe you don't? logic [15:0] a, b; // 16-bit variables
logic [15:0] sumA; // 16-bit variable
logic [16:0] sumB; // 17-bit variable
sumA = a + b; // expression evaluates using 16 bits
sumB = a + b; // expression evaluates using 17 bits I could always add it as a separate warning class but it probably requires some thought to make it actually useful. |
@jrudess, I have tried Even in the case of @MikePopoloski, yes, that is exactly what I want. Although it's a 'feature' in SystemVerilog, I would like to have some sort of strict mode that does not allow the expansion, truncation, or promotion of widths, nor the promotion of integrals to reals, unless explicitly specified. |
b1354ad adds -Warith-op-mismatch, -Wbitwise-op-mismatch, -Wcomparison-mismatch, and -Wsign-compare |
Is your feature request related to a problem? Please describe.
Currently, there doesn't seem to be a warning for binary operation width mismatches, which could be a good feature when using Slang as a linter. For instance, in the following code snippet, there's a typo where
b[pipe]
is mistakenly written asb
, potentially leading to a width mismatch that goes unnoticed:Describe the solution you'd like
I propose adding a compiler warning for binary operation width mismatches or, more broadly, type mismatches.
The text was updated successfully, but these errors were encountered: