Skip to content
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

Testgen: Switch cases can fall through. #3756

Merged
merged 1 commit into from
Dec 7, 2022

Conversation

fruffy-bfn
Copy link
Contributor

Testgen did not model the case where a switch case matches, but falls through to another case. This PR keeps track of a match boolean causes any downstream switch cases to be executed.

for (const auto* switchCase : switchStatement->cases) {
// Nothing to do with this statement, fall through to the next case.
// We have either matched already, or still need to match.
hasMatched = hasMatched || switchStatement->expression->equiv(*switchCase->label);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I don't understand when exactly we'd be changing this flag, i.e. you are doing a reassignment on the LHS, but when we'd be turning that into true?

Copy link
Contributor Author

@fruffy-bfn fruffy-bfn Dec 5, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If isMatched is false but the expression is equivalent to the label isMatched is set to true. After, all subsequent cases should also be executed until we hit a case that has a block statement.

@fruffy fruffy added the p4tools Topics related to the P4Tools back end label Dec 5, 2022
@fruffy fruffy merged commit 0b2a555 into p4lang:main Dec 7, 2022
@fruffy-bfn fruffy-bfn deleted the fruffy/testgen_switch_case branch December 8, 2022 19:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
p4tools Topics related to the P4Tools back end
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants