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

[P4Testgen] Generate NoMatch for selects without default #4250

Merged
merged 4 commits into from
Nov 20, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -377,12 +377,14 @@ bool ExprStepper::preorder(const IR::SelectExpression *selectExpression) {
}

const IR::Expression *missCondition = IR::getBoolLiteral(true);
bool hasDefault = false;
for (const auto *selectCase : selectCases) {
auto &nextState = state.clone();

// Handle case where the first select case matches: proceed to the next parser state,
// guarded by its path condition.
const auto *matchCondition = GenEq::equate(selectExpression->select, selectCase->keyset);
hasDefault = hasDefault || selectCase->keyset->is<IR::DefaultExpression>();

// TODO: Implement the taint case for select expressions.
// In the worst case, this means the entire parser is tainted.
Expand All @@ -408,6 +410,13 @@ bool ExprStepper::preorder(const IR::SelectExpression *selectExpression) {
missCondition = new IR::LAnd(new IR::LNot(matchCondition), missCondition);
}

// generate implicit NoMatch
if (!hasDefault) {
auto &nextState = state.clone();
nextState.replaceTopBody(Continuation::Exception::NoMatch);
result->emplace_back(missCondition, state, nextState);
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
// generate implicit NoMatch
if (!hasDefault) {
auto &nextState = state.clone();
nextState.replaceTopBody(Continuation::Exception::NoMatch);
result->emplace_back(missCondition, state, nextState);
}
// Generate implicit NoMatch.
if (!hasDefault) {
auto &nextState = state.clone();
nextState.replaceTopBody(Continuation::Exception::NoMatch);
result->emplace_back(missCondition, state, nextState);
}


return false;
}

Expand Down
Loading