Pointer::isLocal: if no local ptrs escaped an fncall cant store local ptrs
MODIFY
ir/memory.cpp
ir/memory.cpp
@@ -1167,7 +1167,7 @@ expr Memory::PtrInput::operator==(const PtrInput &rhs) const {
}
expr Memory::mkFnRet(const char *name, const vector<PtrInput> &ptr_inputs) {
- bool has_local = escaped_local_blks.numMayAlias(true);
+ bool has_local = hasEscapedLocals();
unsigned bits_bid = has_local ? bits_for_bid : Pointer::bitsShortBid();
expr var

MODIFY
ir/memory.h
ir/memory.h
@@ -147,6 +147,10 @@ class Memory {
std::vector<unsigned> byval_blks;
AliasSet escaped_local_blks;
+ bool hasEscapedLocals() const {
+ return escaped_local_blks.numMayAlias(true) > 0;
+ }
+
std::map<smt::expr, AliasSet> ptr_alias; // blockid -> alias
unsigned next_nonlocal_bid;
unsigned nextNonlocalBid();

MODIFY
ir/pointer.cpp
ir/pointer.cpp
@@ -126,8 +126,19 @@ expr Pointer::isLocal(bool simplify) const {
auto bit = totalBits() - 1;
expr local = p.extract(bit, bit);
- if (simplify && m.isInitialMemBlock(local))
+ if (simplify) {
+ switch (m.isInitialMemBlock(local, true)) {
+ case 0: break;
+ case 1: return false;
+ case 2:
+ // If no local escaped, pointers written to memory by a callee can't
+ // alias with a local pointer.
+ if (!m.hasEscapedLocals())
return false;
+ break;
+ default: UNREACHABLE();
+ }
+ }
return local == 1;
}

Pointer::isLocal: if no local ptrs escaped an fncall cant store local ptrs