fix crash with undefs in aggregate consts
MODIFY
ir/constant.cpp
ir/constant.cpp
@@ -66,7 +66,7 @@ pair<expr, expr> FloatConst::toSMT_cnst() const {
}
-static string agg_const_str(vector<Constant*> &vals) {
+static string agg_const_str(vector<Value*> &vals) {
string r = "{ ";
bool first = true;
for (auto val : vals) {
@@ -78,14 +78,14 @@ static string agg_const_str(vector<Constant*> &vals) {
return r + " }";
}
-AggregateConst::AggregateConst(Type &type, vector<Constant*> &&vals)
+AggregateConst::AggregateConst(Type &type, vector<Value*> &&vals)
: Constant(type, agg_const_str(vals)), vals(move(vals)) {}
-pair<expr, expr> AggregateConst::toSMT_cnst() const {
+StateValue AggregateConst::toSMT(State &s) const {
expr v;
bool first = true;
for (auto val : vals) {
- auto [vv, vnp] = val->toSMT_cnst();
+ auto [vv, vnp] = val->toSMT(s);
assert(vnp.isTrue());
vv = val->getType().toBV(vv);
v = first ? vv : v.concat(vv);
@@ -94,6 +94,10 @@ pair<expr, expr> AggregateConst::toSMT_cnst() const {
return { move(v), true };
}
+pair<expr, expr> AggregateConst::toSMT_cnst() const {
+ UNREACHABLE();
+}
+
expr AggregateConst::getTypeConstraints() const {
expr r = Value::getTypeConstraints();
vector<Type*> types;

MODIFY
ir/constant.h
ir/constant.h
@@ -28,7 +28,7 @@ class IntConst final : public Constant {
public:
IntConst(Type &type, int64_t val);
IntConst(Type &type, std::string &&val);
- virtual std::pair<smt::expr, smt::expr> toSMT_cnst() const override;
+ std::pair<smt::expr, smt::expr> toSMT_cnst() const override;
smt::expr getTypeConstraints() const override;
auto getInt() const { return std::get_if<int64_t>(&val); }
};
@@ -39,17 +39,18 @@ class FloatConst final : public Constant {
public:
FloatConst(Type &type, double val);
- virtual std::pair<smt::expr, smt::expr> toSMT_cnst() const override;
+ std::pair<smt::expr, smt::expr> toSMT_cnst() const override;
smt::expr getTypeConstraints() const override;
};
class AggregateConst final : public Constant {
- std::vector<Constant*> vals;
+ std::vector<Value*> vals;
public:
- AggregateConst(Type &type, std::vector<Constant*> &&vals);
+ AggregateConst(Type &type, std::vector<Value*> &&vals);
- virtual std::pair<smt::expr, smt::expr> toSMT_cnst() const override;
+ StateValue toSMT(State &s) const override;
+ std::pair<smt::expr, smt::expr> toSMT_cnst() const override;
smt::expr getTypeConstraints() const override;
};
@@ -58,7 +59,7 @@ class ConstantInput final : public Constant {
public:
ConstantInput(Type &type, std::string &&name)
: Constant(type, std::move(name)) {}
- virtual std::pair<smt::expr, smt::expr> toSMT_cnst() const;
+ std::pair<smt::expr, smt::expr> toSMT_cnst() const override;
};

MODIFY
llvm_util/utils.cpp
llvm_util/utils.cpp
@@ -175,9 +175,9 @@ Value* get_operand(llvm::Value *v) {
}
if (auto cnst = dyn_cast<llvm::ConstantAggregate>(v)) {
- vector<Constant*> vals;
+ vector<Value*> vals;
for (auto I = cnst->op_begin(), E = cnst->op_end(); I != E; ++I) {
- vals.emplace_back(static_cast<Constant*>(get_operand(*I)));
+ vals.emplace_back(get_operand(*I));
}
auto val = make_unique<AggregateConst>(*ty, move(vals));
auto ret = val.get();

fix crash with undefs in aggregate consts