p4c icon indicating copy to clipboard operation
p4c copied to clipboard

Type check that RHS of shift is integral type

Open vlstill opened this issue 11 months ago • 3 comments

Fixes #5094. There was no check that RHS of shift is an integral type. In most targets, this was probably a backend error prior, but theoretically this could be a breaking change.

vlstill avatar Jan 15 '25 08:01 vlstill

OK, there is a problem, since the midend usually lowers type-introduced types back to their underlying type, this bug actually allowed shift by values of type introduced by type, e.g. the PortId_t in dpdk/psa.p4. By the spec (8.23. Operations on types introduced by type) this should not be allowed, but that would be far bigger breaking change than I originally thought. This probably needs more discussion on how to resolve it, I'm thinking of explicitly stripping type in the type checker for now to permit this behavior at least temporarily.

EDIT: --> #5100

vlstill avatar Jan 15 '25 11:01 vlstill

According to 8.11.2 in the spec, serializable enums may be implicitly converted to their underlying type, so this code probably needs to deal with that case too.

ChrisDodd avatar Jan 15 '25 20:01 ChrisDodd

Right, let me check if I can reuse some existing check for implicit casts, we don't want these duplicated all around.

vlstill avatar Jan 16 '25 08:01 vlstill

Replaced with #5446.

dmatousek avatar Dec 11 '25 09:12 dmatousek