Skip to content

Commit 0dcec58

Browse files
committed
fix #1244: tail call check must be UB if ptr is poison
1 parent 9880fcf commit 0dcec58

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

ir/attrs.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -672,10 +672,11 @@ void TailCallInfo::check(State &s, const Instr &i,
672672
// Exception: alloca or byval arg may be passed to the callee as byval
673673
for (const auto &arg : args) {
674674
Pointer ptr(s.getMemory(), arg.val.value);
675-
s.addUB(arg.val.non_poison.implies(
675+
// if the ptr is poison, it can be replaced by an alloca
676+
s.addUB(arg.val.non_poison &&
676677
(ptr.isStackAllocated() || ptr.isByval()).implies(arg.byval != 0) &&
677678
true // TODO: check for !var_args
678-
));
679+
);
679680
}
680681

681682
if (type != TailCallInfo::MustTail)
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
define i32 @src() {
2+
entry:
3+
%s = alloca i128, align 8
4+
%x = getelementptr inbounds nuw i8, ptr %s, i64 8
5+
store i32 0, ptr %x, align 8
6+
%0 = load ptr, ptr %s, align 8
7+
%call = tail call i32 @multiply(ptr %0, i32 0)
8+
store ptr %s, ptr %s, align 8
9+
%1 = load i32, ptr %x, align 8
10+
ret i32 %1
11+
}
12+
13+
define i32 @tgt() {
14+
%s = alloca i128, align 8
15+
%call = tail call i32 @multiply(ptr undef, i32 0)
16+
ret i32 0
17+
}
18+
19+
declare i32 @multiply(ptr, i32)

0 commit comments

Comments
 (0)