p4c icon indicating copy to clipboard operation
p4c copied to clipboard

Fix warnings on signed integer initialization

Open AndrzejSawula opened this issue 1 year ago • 2 comments

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.

AndrzejSawula avatar Dec 22 '23 11:12 AndrzejSawula

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

jonathan-dilorenzo avatar Jan 10 '24 17:01 jonathan-dilorenzo

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.

ChrisDodd avatar Feb 05 '24 20:02 ChrisDodd