Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions ir/pointer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -852,9 +852,19 @@ expr Pointer::fninputRefined(const Pointer &other, set<expr> &undef,
auto [p1l, d1] = toLogicalLocal();
auto [p2l, d2] = other.toLogicalLocal();

// TODO: check block value for byval_bytes
if (!byval_bytes.isZero())
return true;
if (!byval_bytes.isZero()) {
uint64_t bytes;
if (!byval_bytes.isUInt(bytes))
return false;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

byval bytes can be a variable. The code needs to support this case or leave the TODO there and return true to avoid false positives. In general this requires doing a memcmp using a lambda (which is not implemented in memory.cpp yet).


expr byval_refined = true;
for (uint64_t off = 0; off < bytes; ++off) {
auto src_byte = m.raw_load(*this + off, undef);
auto tgt_byte = other.m.raw_load(other + off, undef);
byval_refined &= src_byte.refined(tgt_byte);
}
return byval_refined;
}

expr local = d2 && (p2l.isLocal() || p2l.isByval()) &&
at_least_same_offseting(p1l, p2l, false);
Expand Down
23 changes: 23 additions & 0 deletions tests/alive-tv/calls/byval-copy-mismatch.srctgt.ll
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
; ERROR: Source is more defined than target

declare i32 @g(ptr byval(i32))

define i32 @src() {
entry:
%p = alloca i32, align 4
%q = alloca i32, align 4
store i32 1, ptr %p, align 4
store i32 2, ptr %q, align 4
%r = call i32 @g(ptr byval(i32) %p)
ret i32 %r
}

define i32 @tgt() {
entry:
%p = alloca i32, align 4
%q = alloca i32, align 4
store i32 1, ptr %p, align 4
store i32 2, ptr %q, align 4
%r = call i32 @g(ptr byval(i32) %q)
ret i32 %r
}
Loading