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] Fix another segmentation fault when using the coverable nodes scanner. #4203

Merged
merged 1 commit into from
Oct 23, 2023
Merged
Changes from all commits
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
21 changes: 10 additions & 11 deletions backends/p4tools/modules/testgen/core/small_step/cmd_stepper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -508,7 +508,6 @@ bool CmdStepper::preorder(const IR::SwitchStatement *switchStatement) {
std::vector<Continuation::Command> cmds;
// If the switch expression is tainted, we can not predict which case will be chosen. We taint
// the program counter and execute all of the statements.
P4::Coverage::CoverageSet coveredNodes;
if (Taint::hasTaint(switchExpr)) {
auto currentTaint = state.getProperty<bool>("inUndefinedState");
cmds.emplace_back(Continuation::PropertyUpdate("inUndefinedState", true));
Expand All @@ -522,20 +521,14 @@ bool CmdStepper::preorder(const IR::SwitchStatement *switchStatement) {
state.replaceTopBody(&cmds);
return false;
}

// Otherwise, we pick the switch statement case in a normal fashion.
auto &nextState = state.clone();
P4::Coverage::CoverageSet coveredNodes;
bool hasMatched = false;
/// Get the action list associated with this switch/case.
auto switchActionString = switchExpr->checkedTo<IR::StringLiteral>();

auto &nextState = state.clone();
// Otherwise, we pick the switch statement case in a normal fashion.
bool hasMatched = false;
for (const auto *switchCase : switchCases) {
if (requiresLookahead(TestgenOptions::get().pathSelectionPolicy)) {
// Some path selection strategies depend on looking ahead and collecting potential
// nodes. If that is the case, apply the CoverableNodesScanner visitor.
auto collector = CoverableNodesScanner(state);
collector.updateNodeCoverage(switchCase->statement, coveredNodes);
}
// We have either matched already, or still need to match.
hasMatched = hasMatched || switchActionString->value == switchCase->label->toString();
// Nothing to do with this statement. Fall through to the next case.
Expand All @@ -544,6 +537,12 @@ bool CmdStepper::preorder(const IR::SwitchStatement *switchStatement) {
}
// If any of the values in the match list hits, execute the switch case block.
if (hasMatched) {
// Some path selection strategies depend on looking ahead and collecting potential
// nodes. If that is the case, apply the CoverableNodesScanner visitor.
if (requiresLookahead(TestgenOptions::get().pathSelectionPolicy)) {
auto collector = CoverableNodesScanner(state);
collector.updateNodeCoverage(switchCase->statement, coveredNodes);
}
nextState.add(*new TraceEvents::GenericDescription(
"SwitchCase", switchCase->label->getSourceInfo().toBriefSourceFragment()));
cmds.emplace_back(switchCase->statement);
Expand Down
Loading