phi: fix crash when entry comes from unreachable BB
reported in
MODIFY
ir/instr.cpp
ir/instr.cpp
@@ -550,13 +550,16 @@ StateValue Phi::toSMT(State &s) const {
bool first = true;
for (auto &[val, bb] : values) {
+ auto pre = s.jumpCondFrom(s.getFn().getBB(bb));
+ if (!pre) // jump from unreachable BB
+ continue;
+
auto v = s[val];
if (first) {
ret = v;
first = false;
} else {
- expr pre = s.jumpCondFrom(s.getFn().getBB(bb));
- ret = StateValue::mkIf(pre, v, ret);
+ ret = StateValue::mkIf(*pre, v, ret);
}
}
return ret;

MODIFY
ir/state.cpp
ir/state.cpp
@@ -67,8 +67,10 @@ const State::ValTy& State::at(const Value &val) const {
return values[values_map.at(&val)].second;
}
-const expr& State::jumpCondFrom(const BasicBlock &bb) const {
- return predecessor_domain.at(current_bb).at(&bb).first;
+const expr* State::jumpCondFrom(const BasicBlock &bb) const {
+ auto pres = predecessor_domain.at(current_bb);
+ auto I = pres.find(&bb);
+ return I == pres.end() ? nullptr : &I->second.first;
}
bool State::startBB(const BasicBlock &bb) {

MODIFY
ir/state.h
ir/state.h
@@ -81,7 +81,7 @@ public:
const StateValue& exec(const Value &v);
const StateValue& operator[](const Value &val);
const ValTy& at(const Value &val) const;
- const smt::expr& jumpCondFrom(const BasicBlock &bb) const;
+ const smt::expr* jumpCondFrom(const BasicBlock &bb) const;
bool startBB(const BasicBlock &bb);
void addJump(const BasicBlock &dst);

phi: fix crash when entry comes from unreachable BB
reported in #43