change attr's align field to store the value in bytes
MODIFY
ir/attrs.cpp
ir/attrs.cpp
@@ -23,7 +23,7 @@ ostream& operator<<(ostream &os, const ParamAttrs &attr) {
if (attr.has(ParamAttrs::NoUndef))
os << "noundef ";
if (attr.has(ParamAttrs::Align))
- os << "align(" << (1ull << attr.align) << ") ";
+ os << "align(" << attr.align << ") ";
if (attr.has(ParamAttrs::Returned))
os << "returned ";
return os;
@@ -42,7 +42,7 @@ ostream& operator<<(ostream &os, const FnAttrs &attr) {
if (attr.has(FnAttrs::NoReturn))
os << " noreturn";
if (attr.has(FnAttrs::Dereferenceable))
- os << " dereferenceable(" << attr.derefBytes << ")";
+ os << " dereferenceable(" << attr.derefBytes << ')';
if (attr.has(FnAttrs::NonNull))
os << " nonnull";
if (attr.has(FnAttrs::NoFree))
@@ -50,7 +50,7 @@ ostream& operator<<(ostream &os, const FnAttrs &attr) {
if (attr.has(FnAttrs::NoUndef))
os << " noundef";
if (attr.has(FnAttrs::Align))
- os << " align(" << (1ull << attr.align) << ")";
+ os << " align(" << attr.align << ')';
return os;
}

MODIFY
ir/attrs.h
ir/attrs.h
@@ -19,7 +19,7 @@ public:
uint64_t derefBytes; // Dereferenceable
uint64_t blockSize; // exact block size for e.g. byval args
- uint64_t align; // power-of-2 in bytes
+ uint64_t align = 1;
bool has(Attribute a) const { return (bits & a) != 0; }
void set(Attribute a) { bits |= (unsigned)a; }
@@ -54,7 +54,7 @@ public:
void set(Attribute a) { bits |= (unsigned)a; }
uint64_t derefBytes; // Dereferenceable
- uint64_t align; // power-of-2 in bytes
+ uint64_t align = 1;
// Returns true if returning poison or an aggregate having a poison is UB
bool poisonImpliesUB() const

MODIFY
ir/instr.cpp
ir/instr.cpp
@@ -1643,7 +1643,7 @@ static void unpack_inputs(State &s, Value &argv, Type &ty,
s.addUB(p.isNonZero());
if (argflag.has(ParamAttrs::Align))
- s.addUB(p.isAligned(1ull << argflag.align));
+ s.addUB(p.isAligned(argflag.align));
ptr_inputs.emplace_back(StateValue(p.release(), move(value.non_poison)),
argflag.has(ParamAttrs::ByVal),
@@ -1699,7 +1699,7 @@ pack_return(State &s, Type &ty, vector<StateValue> &vals, const FnAttrs &attrs,
if (isNonNull)
s.addUB(p.isNonZero());
if (isAlign)
- s.addUB(p.isAligned(1ull << attrs.align));
+ s.addUB(p.isAligned(attrs.align));
}
return ret;
@@ -2344,7 +2344,7 @@ StateValue Return::toSMT(State &s) const {
s.addUB(p.isNonZero());
}
if (isAlign) {
- s.addUB(p.isAligned(1ull << attrs.align));
+ s.addUB(p.isAligned(attrs.align));
}
}

MODIFY
ir/memory.cpp
ir/memory.cpp
@@ -1585,7 +1585,7 @@ expr Memory::mkInput(const char *name, const ParamAttrs &attrs) {
if (attrs.has(ParamAttrs::NonNull))
state->addAxiom(p.isNonZero());
if (attrs.has(ParamAttrs::Align))
- state->addAxiom(p.isAligned(1ull << attrs.align));
+ state->addAxiom(p.isAligned(attrs.align));
state->addAxiom(bid.ule(max_bid));

MODIFY
llvm_util/llvm2alive.cpp
llvm_util/llvm2alive.cpp
@@ -299,7 +299,7 @@ public:
if (align) {
attrs.set(FnAttrs::Align);
- attrs.align = ilog2(align);
+ attrs.align = align;
}
}
@@ -353,7 +353,7 @@ public:
assert(a);
attr.set(ParamAttrs::Align);
- attr.align = ilog2(a);
+ attr.align = a;
}
if (i.paramHasAttr(argidx, llvm::Attribute::ByVal)) {
@@ -362,7 +362,7 @@ public:
attr.blockSize = DL().getTypeAllocSize(ty);
if (!attr.has(ParamAttrs::Align)) {
attr.set(ParamAttrs::Align);
- attr.align = ilog2(DL().getABITypeAlignment(ty));
+ attr.align = DL().getABITypeAlignment(ty);
}
}
@@ -1043,7 +1043,7 @@ end:
case llvm::Attribute::Alignment:
attrs.set(ParamAttrs::Align);
- attrs.align = ilog2(attr.getAlignment()->value());
+ attrs.align = attr.getAlignment()->value();
continue;
case llvm::Attribute::NoUndef:
@@ -1112,7 +1112,7 @@ end:
unsigned a = f.getAttribute(ridx, llvm::Attribute::Alignment)
.getAlignment()->value();
attrs.set(FnAttrs::Align);
- attrs.align = ilog2(a);
+ attrs.align = a;
}
// create all BBs upfront in topological order

MODIFY
tools/transform.cpp
tools/transform.cpp
@@ -676,8 +676,7 @@ static void calculateAndInitConstants(Transform &t) {
if (!i)
continue;
- uint64_t align = i->hasAttribute(ParamAttrs::Align) ?
- 1ull << i->getAttributes().align : 1;
+ uint64_t align = i->getAttributes().align;
if (i->hasAttribute(ParamAttrs::Dereferenceable)) {
does_mem_access = true;
uint64_t deref_bytes = i->getAttributes().derefBytes;

change attr's align field to store the value in bytes (#594)