p4c
p4c copied to clipboard
Fix warnings on signed integer initialization
Remove misleading overflow warning for correct-width signed integer literals with MSBit set, i.e. representing negative numbers. This is actually the only way integer literals of explicitly-declared width can be specified (as per language specs, Section 6.3.3.2).
As these warnings are mentioned in the language specs, Section 7.1.6.6, this change is accompanied with one to the specs content, PR #1270.
It looks like this didn't come up yet in the corresponding spec change, but, based on discussions in the LDWG, I think we'd prefer to keep the warnings on signed integer initialization unless you have a use-case that doesn't fit our imagination in mind. Let me add a comment to the specification issue: github.com/p4lang/p4-spec/issues/1269
I've been experimenting a bit with this and another implementation issue I see is that it does not appear to be possible to stop specific warnings with explicit casts -- that is, something like (bit<8>)10w256
will give a warning about 256 being out of range for a bit<8>
. This seems wrong (and will cause problems when using -Werror
if you have code that wants the expected modulo behavior for the code). This should probably be a separate bug filed against p4c.