fix crash when storing values that aren't multiple of 8 bits
MODIFY
ir/memory.cpp
ir/memory.cpp
@@ -266,7 +266,7 @@ void Memory::store(const expr &p, const StateValue &v, Type &type,
unsigned bits = val.bits();
unsigned bytes = divide_up(bits, 8);
- val.value = val.value.zext(bytes * 8 - bits);
+ val = val.zext(bytes * 8 - bits);
Pointer ptr(*this, p);
ptr.is_dereferenceable(bytes, align);
@@ -291,11 +291,8 @@ StateValue Memory::load(const expr &p, Type &type, unsigned align) {
for (unsigned i = 0; i < bytes; ++i) {
auto ptr_i = (ptr + i).release();
expr pair = blocks_val.load(ptr_i);
- expr v = pair.extract(7, 0);
- expr p = pair.extract(15, 8);
-
- val.value = first ? move(v) : v.concat(val.value);
- val.non_poison = first ? move(p) : p.concat(val.non_poison);
+ StateValue v(pair.extract(7, 0), pair.extract(15, 8));
+ val = first ? move(v) : v.concat(val);
first = false;
}

MODIFY
ir/state_value.cpp
ir/state_value.cpp
@@ -14,6 +14,10 @@ StateValue StateValue::mkIf(const expr &cond, const StateValue &then,
expr::mkIf(cond, then.non_poison, els.non_poison) };
}
+StateValue StateValue::zext(unsigned amount) const {
+ return { value.zext(amount), non_poison.zext(amount) };
+}
+
StateValue StateValue::concat(const StateValue &other) const {
return { value.concat(other.value), non_poison.concat(other.non_poison) };
}

MODIFY
ir/state_value.h
ir/state_value.h
@@ -22,7 +22,9 @@ struct StateValue {
auto bits() const { return value.bits(); }
+ StateValue zext(unsigned amount) const;
StateValue concat(const StateValue &other) const;
+
smt::expr both() const { return value && non_poison; }
bool eq(const StateValue &other) const;

fix crash when storing values that aren't multiple of 8 bits