-
Notifications
You must be signed in to change notification settings - Fork 455
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Compiler Bug
in simplifySwitch.cpp
#5120
Comments
@kfcripps the issue you are facing is most probably because many languages take arg of switch as int or enum not bool. So you can use if-else instead of switch statement here |
@Vineet1101 I don't think that's the problem here.. Attached below is a simplified reproducer, which has a
|
Also, if |
Anything that throws a "Compiler Bug" is a problem in the compiler that needs to be fixed. |
@kfcripps the P4_16 specification (at least for versions up to v1.2.1) requires that the switch expression be of the form derived from a table apply—so that the case labels correspond to action names. When you try to switch on “a” (a plain boolean) and label the case with the identifier “b” (which in this context is not a constant expression but a variable name), p4c doesn’t know how to process it and fails with an “Unexpected expression a” similarly in the next example which you gave switch is applied using an arbitrary expression( bit<16> a) . This unsupported use causes the internal compiler logic to encounter an unexpected expression and crash. here's the document |
That's no longer the case. The spec is currently a bit unclear with respect to this feature, but generalized In fact, there exists test issue3299.p4, which shows that the |
The problem is the following: The type checker marks
I suspect that other things might break if the type checker does not mark directionless params as compile-time constants, so at the moment I'm not sure how to fix it (maybe |
I am not sure if there is confusion on this point, but I wanted to point it out, in case there is. Note the following sentence near the beginning of the article you linked to: "This article is not part of the P4_16 language specification because it is simply one possible way to implement these generalized switch statements." There are many ways to implement switch statements in p4c. I wrote that article since it seemed to be a relatively low effort strategy for generalizing switch statements in p4c and behavioral-model implementations at the time, because they both already had support for the If someone wants to support |
Building the following P4 program:
results in:
The text was updated successfully, but these errors were encountered: