simplify nofree
MODIFY
ir/instr.cpp
ir/instr.cpp
@@ -1497,6 +1497,11 @@ StateValue FnCall::toSMT(State &s) const {
auto ret = s.addFnCall(fnName_mangled.str(), move(inputs), move(ptr_inputs),
out_types, attrs);
+ // Caller has nofree attribute, so callee must have it as well
+ if (s.getFn().getFnAttrs().has(FnAttrs::NoFree) &&
+ !attrs.has(FnAttrs::NoFree))
+ s.addUB(expr(false));
+
if (attrs.has(FnAttrs::NoReturn)) {
// TODO: Even if a function call doesn't have noreturn, it can possibly
// exit. Relevant bug: https://bugs.llvm.org/show_bug.cgi?id=27953

MODIFY
ir/memory.cpp
ir/memory.cpp
@@ -1714,11 +1714,6 @@ expr Memory::checkNocapture() const {
return res;
}
-expr Memory::checkNoFree(const CallState &state_after) const {
- // TODO: encode local block's liveness
- return state_after.non_local_block_liveness == non_local_block_liveness;
-}
-
Memory Memory::mkIf(const expr &cond, const Memory &then, const Memory &els) {
assert(then.state == els.state);
Memory ret(then);

MODIFY
ir/memory.h
ir/memory.h
@@ -310,7 +310,6 @@ public:
// Returns true if a nocapture pointer byte is not in the memory.
smt::expr checkNocapture() const;
- smt::expr checkNoFree(const CallState &state_after) const;
unsigned numLocals() const;
unsigned numNonlocals() const;

MODIFY
ir/state.cpp
ir/state.cpp
@@ -276,10 +276,6 @@ State::addFnCall(const string &name, vector<StateValue> &&inputs,
addUB(I->second.ub);
- // Caller has nofree attribute; callee should guarantee that it didn't free
- if (getFn().getFnAttrs().has(FnAttrs::NoFree))
- addUB(memory.checkNoFree(I->second.callstate));
-
if (writes_memory)
memory.setState(I->second.callstate);

ADD
tests/alive-tv/attrs/nofree2.srctgt.ll
+define void @src() nofree {
+ call void @fn()
+ ret void
+}
+
+define void @tgt() nofree {
+ unreachable
+}
+
+declare void @fn()

ADD
tests/alive-tv/attrs/nofree3.srctgt.ll
+define void @src() nofree {
+ call void @fn()
+ ret void
+}
+
+define void @tgt() nofree {
+ unreachable
+}
+
+; ERROR: Source is more defined than target
+
+declare void @fn() nofree

simplify nofree