p4lang / p4c

P4_16 reference compiler
https://p4.org/
Apache License 2.0
681 stars 445 forks source link

Incorrect unrolling of for loop #4965

Closed jafingerhut closed 1 month ago

jafingerhut commented 1 month ago

See the attached test program. As of 2024-Oct-16, the latest p4c unrolls the loop as if it terminates, but it is actually an infinite loop. loop-3-clause-tricky1.p4.txt

@ChrisDodd

jafingerhut commented 1 month ago

The second attached program has a finite loop, but p4c unrolls it with only 2 iterations, when it should have 4 iterations

loop-3-clause-tricky2.p4.txt

What these examples have in common is that the loop variable wraps around during one or more update steps.

jafingerhut commented 1 month ago

Closing this issue, as it is now fixed by this PR: https://github.com/p4lang/p4c/pull/4967