Skip to content

Commit

Permalink
fix false positive with noread fn calls with local block passed as input
Browse files Browse the repository at this point in the history
  • Loading branch information
nunoplopes committed Dec 4, 2023
1 parent 68ff734 commit 3e1e364
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 1 deletion.
7 changes: 7 additions & 0 deletions ir/memory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1196,6 +1196,13 @@ Memory::Memory(State &state) : state(&state), escaped_local_blks(*this) {
}
}

Memory Memory::dupNoRead() const {
Memory ret(*state);
// minimal state to allow fn calls to compare input fn ptrs that can't be read
ret.local_blk_addr = local_blk_addr;
return ret;
}

void Memory::mkAxioms(const Memory &tgt) const {
assert(state->isSource() && !tgt.state->isSource());
if (memory_unused())
Expand Down
1 change: 1 addition & 0 deletions ir/memory.h
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,7 @@ class Memory {
Memory& operator=(Memory&&) = default;

Memory dup() const { return *this; }
Memory dupNoRead() const;

void mkAxioms(const Memory &other) const;

Expand Down
2 changes: 1 addition & 1 deletion ir/state.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1014,7 +1014,7 @@ State::addFnCall(const string &name, vector<StateValue> &&inputs,
auto call_data_pair
= calls_fn.try_emplace(
{ std::move(inputs), std::move(ptr_inputs), std::move(call_ranges),
attrs.mem.canReadSomething() ? memory.dup() : Memory(*this),
attrs.mem.canReadSomething() ? memory.dup() : memory.dupNoRead(),
attrs.mem, noret, willret });
auto &I = call_data_pair.first;
bool inserted = call_data_pair.second;
Expand Down
14 changes: 14 additions & 0 deletions tests/alive-tv/calls/noread.srctgt.ll
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
define ptr @src() {
%call = call nonnull ptr @_Znwm(i64 8)
call void @fn(ptr %call) memory(argmem:write)
ret ptr %call
}

define ptr @tgt() {
%call = call nonnull ptr @_Znwm(i64 8)
call void @fn(ptr %call) memory(argmem:write)
ret ptr %call
}

declare ptr @_Znwm(i64)
declare void @fn(ptr)

0 comments on commit 3e1e364

Please sign in to comment.