fix some crashes with gep
MODIFY
ir/instr.cpp
ir/instr.cpp
@@ -954,18 +954,19 @@ StateValue GEP::toSMT(State &s) const {
auto [val, non_poison] = s[ptr];
unsigned bits_offset = s.getMemory().bitsOffset();
+ Pointer ptr(s.getMemory(), move(val));
if (inbounds)
- non_poison &= Pointer(s.getMemory(), val).inbounds();
+ non_poison &= ptr.inbounds();
for (auto &[sz, idx] : idxs) {
auto &[v, np] = s[idx];
- val = val + expr::mkUInt(sz, bits_offset) * v.sextOrTrunc(bits_offset);
+ ptr += expr::mkUInt(sz, bits_offset) * v.sextOrTrunc(bits_offset);
non_poison &= np;
if (inbounds)
- non_poison &= Pointer(s.getMemory(), val).inbounds();
+ non_poison &= ptr.inbounds();
}
- return { move(val), move(non_poison) };
+ return { ptr.release(), move(non_poison) };
}
expr GEP::getTypeConstraints(const Function &f) const {

MODIFY
ir/memory.cpp
ir/memory.cpp
@@ -34,13 +34,17 @@ expr Pointer::get_offset() const {
}
void Pointer::operator++(void) {
- p = (get_offset() + expr::mkUInt(1, m.bits_for_offset)).concat(get_bid());
+ *this += expr::mkUInt(1, m.bits_for_offset);
}
Pointer Pointer::operator+(const expr &bytes) const {
return { m, (get_offset() + bytes).concat(get_bid()) };
}
+void Pointer::operator+=(const expr &bytes) {
+ p = (get_offset() + bytes).concat(get_bid());
+}
+
expr Pointer::ult(const Pointer &rhs) const {
return get_bid() == rhs.get_bid() && get_offset().ult(rhs.get_offset());
}

MODIFY
ir/memory.h
ir/memory.h
@@ -26,10 +26,12 @@ public:
smt::expr get_offset() const;
const smt::expr& operator()() const { return p; }
+ smt::expr&& release() { return std::move(p); }
unsigned bits() const { return p.bits(); }
void operator++(void);
Pointer operator+(const smt::expr &bytes) const;
+ void operator+=(const smt::expr &bytes);
smt::expr ult(const Pointer &rhs) const;
smt::expr uge(const Pointer &rhs) const;

MODIFY
llvm_util/utils.cpp
llvm_util/utils.cpp
// Distributed under the MIT license that can be found in the LICENSE file.
#include "llvm_util/utils.h"
-#include "util/compiler.h"
#include "llvm/IR/GetElementPtrTypeIterator.h"
#include "llvm/IR/InstVisitor.h"
#include "llvm/IR/Operator.h"
using namespace IR;
using namespace std;
-using namespace util;
using llvm::cast, llvm::dyn_cast, llvm::isa;
using llvm::LLVMContext;
@@ -188,6 +186,8 @@ class llvm2alive_ : public llvm::InstVisitor<llvm2alive_, unique_ptr<Instr>> {
llvm::Function &f;
using RetTy = unique_ptr<Instr>;
+ auto DL() const { return f.getParent()->getDataLayout(); }
+
public:
llvm2alive_(llvm::Function &f) : f(f) {}
@@ -304,10 +304,8 @@ public:
if (!ty)
return error(i);
- // FIXME: bring in DL data
- unsigned sz = divide_up(i.getAllocatedType()->getPrimitiveSizeInBits(), 8);
// FIXME: size bits shouldn't be a constant
- auto size = make_intconst(sz, 64);
+ auto size = make_intconst(DL().getTypeAllocSize(i.getAllocatedType()), 64);
RETURN_IDENTIFIER(make_unique<Alloc>(*ty, value_name(i), *size,
i.getAlignment()));
}
@@ -331,9 +329,7 @@ public:
if (I.getStructTypeOrNull())
return error(i);
- // FIXME: bring in DL data
- unsigned sz = divide_up(I.getIndexedType()->getPrimitiveSizeInBits(), 8);
- gep->addIdx(sz, *op);
+ gep->addIdx(DL().getTypeAllocSize(I.getIndexedType()), *op);
}
RETURN_IDENTIFIER(move(gep));
}

fix some crashes with gep