add support for align metadata (used by ret value of loads)
MODIFY
ir/instr.cpp
ir/instr.cpp
@@ -3140,6 +3140,9 @@ AssumeVal::AssumeVal(Type &type, string &&name, Value &val,
: Instr(type, std::move(name)), val(&val), args(std::move(args0)),
kind(kind) {
switch (kind) {
+ case Align:
+ assert(args.size() == 1);
+ break;
case NonNull:
assert(args.empty());
break;
@@ -3164,6 +3167,7 @@ void AssumeVal::rauw(const Value &what, Value &with) {
void AssumeVal::print(ostream &os) const {
const char *str = nullptr;
switch (kind) {
+ case Align: str = "align "; break;
case NonNull: str = "nonnull "; break;
case Range: str = "range "; break;
}
@@ -3180,6 +3184,12 @@ StateValue AssumeVal::toSMT(State &s) const {
expr np;
switch (kind) {
+ case Align:
+ uint64_t n;
+ ENSURE(s[*args[0]].value.isUInt(n));
+ np = Pointer(s.getMemory(), expr(v.value)).isAligned(n);
+ break;
+
case NonNull:
np = !Pointer(s.getMemory(), expr(v.value)).isNull();
break;
@@ -3209,6 +3219,9 @@ StateValue AssumeVal::toSMT(State &s) const {
expr AssumeVal::getTypeConstraints(const Function &f) const {
expr e = true;
switch (kind) {
+ case Align:
+ e = args[0]->getType().isIntType();
+ break;
case NonNull:
break;
case Range:

MODIFY
ir/instr.h
ir/instr.h
@@ -589,6 +589,7 @@ public:
class AssumeVal final : public Instr {
public:
enum Kind {
+ Align,
NonNull,
Range,
};

MODIFY
llvm_util/llvm2alive.cpp
llvm_util/llvm2alive.cpp
@@ -1199,20 +1199,23 @@ public:
for (auto &[ID, Node] : MDs) {
switch (ID) {
+ case LLVMContext::MD_align:
case LLVMContext::MD_nonnull:
case LLVMContext::MD_range:
{
vector<Value*> args;
- for (unsigned op = 0, e = Node->getNumOperands(); op < e; ++op) {
+ for (auto &Op : Node->operands()) {
args.emplace_back(get_operand(
- llvm::mdconst::extract<llvm::ConstantInt>(Node->getOperand(op))));
- args.emplace_back(get_operand(
- llvm::mdconst::extract<llvm::ConstantInt>(Node->getOperand(++op))));
+ llvm::mdconst::extract<llvm::ConstantInt>(Op)));
}
AssumeVal::Kind op;
const char *str = nullptr;
switch (ID) {
+ case LLVMContext::MD_align:
+ op = AssumeVal::Align;
+ str = "_align";
+ break;
case LLVMContext::MD_nonnull:
op = AssumeVal::NonNull;
str = "_nonnull";

add support for align metadata (used by ret value of loads)