Skip to content

Commit aa2d35d

Browse files
Merge pull request #10559 from swiftlang/cherry-pick-auto-upgrade-6.2
[release/6.2] Fix infinite looping when loading a LLVM bitcode module that has llvm.coro.id.retcon.once intrinsics
2 parents dc1beb9 + 40e2f9c commit aa2d35d

File tree

3 files changed

+60
-1
lines changed

3 files changed

+60
-1
lines changed

llvm/lib/IR/AutoUpgrade.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1073,7 +1073,7 @@ static bool upgradeIntrinsicFunction1(Function *F, Function *&NewFn,
10731073
return true;
10741074
}
10751075

1076-
if (F->arg_size() == 6 && Name == "coro.id.retcon.once") {
1076+
if (!F->isVarArg() && Name == "coro.id.retcon.once") {
10771077
rename(F);
10781078
NewFn = Intrinsic::getDeclaration(F->getParent(),
10791079
Intrinsic::coro_id_retcon_once);
Binary file not shown.
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
; RUN: llvm-dis < %S/Inputs/coro-retcon-frame-auto-upgrade-test.ll.bc 2>&1 | FileCheck %s
2+
3+
; ModuleID = '../llvm-project/llvm/test/Transforms/Coroutines/coro-retcon-frame-auto-upgrade.bc'
4+
; CHECK: source_filename = "../llvm-project/llvm/test/Transforms/Coroutines/coro-retcon-frame-auto-upgrade.ll"
5+
; CHECK: target datalayout = "p:64:64:64"
6+
7+
; CHECK: declare void @prototype_f(ptr, i1)
8+
9+
; CHECK: declare noalias ptr @allocate(i32)
10+
11+
; CHECK: declare void @deallocate(ptr)
12+
13+
; CHECK: declare void @init(ptr)
14+
15+
; CHECK: declare void @use(ptr)
16+
17+
; CHECK: declare void @use_addr_val(i64, ptr)
18+
19+
; Function Attrs: presplitcoroutine
20+
; CHECK: define { ptr, ptr } @f(ptr %buffer) #0 {
21+
; CHECK: entry:
22+
; CHECK: %tmp = alloca { i64, i64 }, align 8
23+
; CHECK: %proj.1 = getelementptr inbounds { i64, i64 }, ptr %tmp, i64 0, i32 0
24+
; CHECK: %proj.2 = getelementptr inbounds { i64, i64 }, ptr %tmp, i64 0, i32 1
25+
; CHECK: store i64 0, ptr %proj.1, align 8
26+
; CHECK: store i64 0, ptr %proj.2, align 8
27+
; CHECK: %escape_addr = ptrtoint ptr %tmp to i64
28+
; CHECK: %id = call token (i32, i32, ptr, ptr, ptr, ptr, ...) @llvm.coro.id.retcon.once(i32 32, i32 8, ptr %buffer, ptr @prototype_f, ptr @allocate, ptr @deallocate)
29+
; CHECK: %hdl = call ptr @llvm.coro.begin(token %id, ptr null)
30+
; CHECK: %proj.2.2 = getelementptr inbounds { i64, i64 }, ptr %tmp, i64 0, i32 1
31+
; CHECK: call void @init(ptr %proj.1)
32+
; CHECK: call void @init(ptr %proj.2.2)
33+
; CHECK: call void @use_addr_val(i64 %escape_addr, ptr %tmp)
34+
; CHECK: %abort = call i1 (...) @llvm.coro.suspend.retcon.i1(ptr %tmp)
35+
; CHECK: br i1 %abort, label %end, label %resume
36+
37+
; CHECK: resume: ; preds = %entry
38+
; CHECK: call void @use(ptr %tmp)
39+
; CHECK: br label %end
40+
41+
; CHECK: end: ; preds = %resume, %entry
42+
; CHECK: %0 = call i1 @llvm.coro.end(ptr %hdl, i1 false, token none)
43+
; CHECK: unreachable
44+
; CHECK: }
45+
46+
; Function Attrs: nounwind
47+
; CHECK: declare ptr @llvm.coro.begin(token, ptr writeonly) #1
48+
49+
; Function Attrs: nounwind
50+
; CHECK: declare i1 @llvm.coro.suspend.retcon.i1(...) #1
51+
52+
; Function Attrs: nounwind
53+
; CHECK: declare i1 @llvm.coro.end(ptr, i1, token) #1
54+
55+
; Function Attrs: nounwind
56+
; CHECK: declare token @llvm.coro.id.retcon.once(i32, i32, ptr, ptr, ptr, ptr, ...) #1
57+
58+
; CHECK: attributes #0 = { presplitcoroutine }
59+
; CHECK: attributes #1 = { nounwind }

0 commit comments

Comments
 (0)