don't store padding bytes in aggregate constants to save memory
MODIFY
ir/type.cpp
ir/type.cpp
@@ -867,9 +867,11 @@ expr AggregateType::enforceAggregateType(vector<Type*> *element_types) const {
if (children.size() < element_types->size())
return false;
- expr r = numElements() == element_types->size();
- for (unsigned i = 0, e = element_types->size(); i != e; ++i) {
- r &= *children[i] == *(*element_types)[i];
+ expr r = numElementsExcludingPadding() == element_types->size();
+ auto types = element_types->begin(), types_E = element_types->end();
+ for (unsigned i = 0, e = children.size(); i != e && types != types_E; ++i) {
+ if (!isPadding(i))
+ r &= *children[i] == **types++;
}
return r;
}

MODIFY
ir/value.cpp
ir/value.cpp
@@ -115,27 +115,28 @@ StateValue GlobalVariable::toSMT(State &s) const {
}
-static string agg_str(vector<Value*> &vals) {
+static string agg_str(const Type &ty, vector<Value*> &vals) {
+ auto agg = ty.getAsAggregateType();
string r = "{ ";
- bool first = true;
- for (auto val : vals) {
- if (!first)
+ unsigned j = 0;
+ for (unsigned i = 0, e = agg->numElementsConst(); i != e; ++i) {
+ if (i != 0)
r += ", ";
- r += val->getName();
- first = false;
+ if (agg->isPadding(i))
+ r += "[padding]";
+ else
+ r += vals[j++]->getName();
}
return r + " }";
}
AggregateValue::AggregateValue(Type &type, vector<Value*> &&vals)
- : Value(type, agg_str(vals)), vals(move(vals)) {}
+ : Value(type, agg_str(type, vals)), vals(move(vals)) {}
StateValue AggregateValue::toSMT(State &s) const {
vector<StateValue> state_vals;
- auto agg = getType().getAsAggregateType();
- for (unsigned i = 0, e = vals.size(); i < e; ++i) {
- if (!agg->isPadding(i))
- state_vals.emplace_back(vals[i]->toSMT(s));
+ for (auto *val : vals) {
+ state_vals.emplace_back(val->toSMT(s));
}
return getType().getAsAggregateType()->aggregateVals(state_vals);
}
@@ -143,7 +144,7 @@ StateValue AggregateValue::toSMT(State &s) const {
expr AggregateValue::getTypeConstraints() const {
expr r = Value::getTypeConstraints();
vector<Type*> types;
- for (auto val : vals) {
+ for (auto *val : vals) {
types.emplace_back(&val->getType());
if (dynamic_cast<const Instr*>(val))
// Instr's type constraints are already generated by BasicBlock's

MODIFY
llvm_util/utils.cpp
llvm_util/utils.cpp
@@ -341,15 +341,7 @@ Value* get_operand(llvm::Value *v,
unsigned opi = 0;
for (unsigned i = 0; i < aty->numElementsConst(); ++i) {
- if (aty->isPadding(i)) {
- auto &padty = aty->getChild(i);
- assert(padty.isIntType());
- auto poison = make_unique<PoisonValue>(padty);
- auto ret = poison.get();
-
- current_fn->addConstant(move(poison));
- vals.emplace_back(ret);
- } else {
+ if (!aty->isPadding(i)) {
if (auto op = get_operand(get_elem(opi), constexpr_conv, copy_inserter))
vals.emplace_back(op);
else

don't store padding bytes in aggregate constants to save memory