llvm: fix crash with void fns without return stmt
MODIFY
ir/instr.cpp
ir/instr.cpp
@@ -1243,7 +1243,10 @@ void Return::rauw(const Value &what, Value &with) {
}
void Return::print(ostream &os) const {
- os << "ret " << print_type(getType()) << val->getName();
+ os << "ret ";
+ if (&getType() != &Type::voidTy)
+ os << print_type(getType());
+ os << val->getName();
}
StateValue Return::toSMT(State &s) const {

MODIFY
ir/value.cpp
ir/value.cpp
@@ -34,9 +34,8 @@ void Value::fixupTypes(const Model &m) {
ostream& operator<<(ostream &os, const Value &val) {
auto t = val.getType().toString();
- if (!t.empty())
os << t;
- if (!dynamic_cast<VoidType*>(&val.getType())) {
+ if (&val.getType() != &Type::voidTy) {
if (!t.empty()) os << ' ';
os << val.getName();
}

MODIFY
llvm_util/utils.cpp
llvm_util/utils.cpp
@@ -754,6 +754,13 @@ public:
}
}
+ // infinite void functions may not have a return stmt in LLVM
+ if (!Fn.hasReturn()) {
+ assert(f.getReturnType()->isVoidTy());
+ Fn.getBBs().back()->addInstr(
+ make_unique<Return>(Type::voidTy, Value::voidVal));
+ }
+
return move(Fn);
}
};

llvm: fix crash with void fns without return stmt