memory: fix a few byval todos
MODIFY
ir/memory.cpp
ir/memory.cpp
@@ -1547,10 +1547,7 @@ pair<expr, expr> Memory::mkUndefInput(const ParamAttrs &attrs) const {
pair<expr,expr>
Memory::mkFnRet(const char *name, const vector<PtrInput> &ptr_inputs) {
for (auto &in : ptr_inputs) {
- if (in.val.non_poison.isFalse())
- continue;
-
- // TODO: callee cannot observe the bid if this is byval.
+ if (!in.byval && !in.nocapture && !in.val.non_poison.isFalse())
escapeLocalPtr(in.val.value);
}
bool has_local = escaped_local_blks.numMayAlias(true);
@@ -1619,9 +1616,9 @@ Memory::mkCallState(const vector<PtrInput> *ptr_inputs, bool nofree) const {
for (unsigned bid = num_consts; bid < num_nonlocals_src; ++bid) {
expr modifies(false);
for (auto &ptr_in : *ptr_inputs) {
- // TODO: byval's value cannot be modified.
- Pointer argp(*this, ptr_in.val.value);
- modifies |= ptr_in.val.non_poison && argp.getBid() == bid;
+ if (!ptr_in.byval) {
+ modifies |= Pointer(*this, ptr_in.val.value).getBid() == bid;
+ }
}
auto &new_val = st.non_local_block_val[bid - num_consts];
@@ -1635,16 +1632,16 @@ Memory::mkCallState(const vector<PtrInput> *ptr_inputs, bool nofree) const {
expr zero = expr::mkUInt(0, num_nonlocals);
expr mask = has_null_block ? one : zero;
for (unsigned bid = has_null_block; bid < num_nonlocals; ++bid) {
- expr ok_arg = true;
+ expr may_free = true;
if (ptr_inputs) {
+ may_free = false;
for (auto &ptr_in : *ptr_inputs) {
- // TODO: liveness of a pointer given as byval doesn't change
- ok_arg &= !ptr_in.val.non_poison ||
- Pointer(*this, ptr_in.val.value).getBid() != bid;
+ if (!ptr_in.byval)
+ may_free |= Pointer(*this, ptr_in.val.value).getBid() == bid;
}
}
expr heap = Pointer(*this, bid, false).isHeapAllocated();
- mask = mask | expr::mkIf(heap && ok_arg,
+ mask = mask | expr::mkIf(heap && may_free,
zero,
one << expr::mkUInt(bid, num_nonlocals));
}

DELETE
tests/alive-tv/skip-smt.srctgt.ll
-; TEST-ARGS: -skip-smt
-
-define i8 @src(i8 %x, i8 %y) {
- %v = add i8 %x, %y
- ret i8 %v
-}
-
-define i8 @tgt(i8 %x, i8 %y) {
- %v = add i8 %y, %x
- ret i8 %v
-}
-
-; ERROR: Skip

MODIFY
tools/transform.cpp
tools/transform.cpp
@@ -690,7 +690,6 @@ static void calculateAndInitConstants(Transform &t) {
};
// The number of bits needed to encode pointer attributes
// nonnull and byval isn't encoded in ptr attribute bits
- bool has_byval = has_attr(ParamAttrs::ByVal);
has_nocapture = has_attr(ParamAttrs::NoCapture);
has_readonly = has_attr(ParamAttrs::ReadOnly);
has_readnone = has_attr(ParamAttrs::ReadNone);
@@ -727,8 +726,6 @@ static void calculateAndInitConstants(Transform &t) {
}
}
}
- if (has_byval)
- min_access_size = 1;
bits_byte = 8 * ((does_mem_access || num_globals != 0)
? (unsigned)min_access_size : 1);

memory: fix a few byval todos