p4c icon indicating copy to clipboard operation
p4c copied to clipboard

./p4_16_errors/div1.p4 is incorrectly rejected for negative values

Open apinski-cavium opened this issue 3 years ago • 1 comments

The testcase is

action act() {
    bit<8> a;
    a = a / -1;
    a = -5 / a;
    a = a % -1;
    a = -5 % a;
}

But -1 here is really -8w1 (aka 8w0xff) and not -1. -5 should be similar too. It looks like the check for negativeness happens before the implicit conversion happens. I noticed this while using my frontend with testcases (after converting them into a format for the testsuite I use).

apinski-cavium avatar Oct 21 '22 06:10 apinski-cavium

I don't think the spec says which happens first: the conversion or the check. So this looks like a legal behavior. The main question is whether we need to change the spec. I think from a usability point of view these programs are wrong, even if the conversion happens first, because they will give a very different result than what the user is probably expecting.

mihaibudiu avatar Oct 21 '22 22:10 mihaibudiu

@jnfoster what does Petra do here?

mihaibudiu avatar Jan 06 '23 21:01 mihaibudiu

Petr4 accepts it.

jnfoster avatar Jan 17 '23 16:01 jnfoster