1; RUN: opt < %s -O0 -S | FileCheck --check-prefixes=CHECK %s 2 3%swift.async_func_pointer = type <{ i32, i32 }> 4%swift.context = type { %swift.context*, void (%swift.context*)*, i64 } 5%T10RR13AC = type <{ %swift.refcounted, %swift.defaultactor }> 6%swift.refcounted = type { %swift.type*, i64 } 7%swift.type = type { i64 } 8%swift.defaultactor = type { [10 x i8*] } 9%swift.bridge = type opaque 10%swift.error = type opaque 11%swift.executor = type {} 12 13@repoTU = hidden global %swift.async_func_pointer <{ i32 trunc (i64 sub (i64 ptrtoint (void (%swift.context*, i64, i64, %T10RR13AC*)* @repo to i64), i64 ptrtoint (%swift.async_func_pointer* @repoTU to i64)) to i32), i32 20 }>, section "__TEXT,__const", align 8 14 15declare void @use(i8*) 16 17; This used to crash. 18; CHECK: repo 19define hidden swifttailcc void @repo(%swift.context* swiftasync %arg, i64 %arg1, i64 %arg2, %T10RR13AC* swiftself %arg3) #0 { 20entry: 21 %i = alloca %swift.context*, align 8 22 %i11 = call token @llvm.coro.id.async(i32 20, i32 16, i32 0, i8* bitcast (%swift.async_func_pointer* @repoTU to i8*)) 23 %i12 = call i8* @llvm.coro.begin(token %i11, i8* null) 24 %i18 = call i8* @llvm.coro.async.resume() 25 call void @use(i8* %i18) 26 %i21 = call { i8* } (i32, i8*, i8*, ...) @llvm.coro.suspend.async.sl_p0i8s(i32 0, i8* %i18, i8* bitcast (i8* (i8*)* @__swift_async_resume_get_context to i8*), i8* bitcast (void (i8*, %swift.executor*, %swift.context*)* @__swift_suspend_point to i8*), i8* %i18, %swift.executor* null, %swift.context* null) 27 %i22 = extractvalue { i8* } %i21, 0 28 %i23 = call i8* @__swift_async_resume_get_context(i8* %i22) 29 %i28 = icmp eq i64 %arg2, 0 30 br i1 %i28, label %bb126, label %bb 31 32bb: ; preds = %entry 33 %i29 = inttoptr i64 %arg2 to %swift.bridge* 34 br label %bb30 35 36bb30: ; preds = %bb 37 %i31 = phi i64 [ %arg1, %bb ] 38 %i32 = phi %swift.bridge* [ %i29, %bb ] 39 %i35 = ptrtoint %swift.bridge* %i32 to i64 40 %i36 = bitcast %T10RR13AC* %arg3 to %swift.type** 41 %i37 = load %swift.type*, %swift.type** %i36, align 8 42 %i38 = bitcast %swift.type* %i37 to void (%swift.context*, i64, i64, %T10RR13AC*)** 43 %i39 = getelementptr inbounds void (%swift.context*, i64, i64, %T10RR13AC*)*, void (%swift.context*, i64, i64, %T10RR13AC*)** %i38, i64 11 44 %i40 = load void (%swift.context*, i64, i64, %T10RR13AC*)*, void (%swift.context*, i64, i64, %T10RR13AC*)** %i39, align 8 45 %i41 = bitcast void (%swift.context*, i64, i64, %T10RR13AC*)* %i40 to %swift.async_func_pointer* 46 %i42 = getelementptr inbounds %swift.async_func_pointer, %swift.async_func_pointer* %i41, i32 0, i32 0 47 %i43 = load i32, i32* %i42, align 8 48 %i44 = sext i32 %i43 to i64 49 %i45 = ptrtoint i32* %i42 to i64 50 %i46 = add i64 %i45, %i44 51 %i47 = inttoptr i64 %i46 to i8* 52 %i48 = bitcast i8* %i47 to void (%swift.context*, i64, i64, %T10RR13AC*)* 53 %i52 = call swiftcc i8* @swift_task_alloc(i64 24) #1 54 %i53 = bitcast i8* %i52 to <{ %swift.context*, void (%swift.context*)*, i32 }>* 55 %i54 = load %swift.context*, %swift.context** %i, align 8 56 %i55 = getelementptr inbounds <{ %swift.context*, void (%swift.context*)*, i32 }>, <{ %swift.context*, void (%swift.context*)*, i32 }>* %i53, i32 0, i32 0 57 store %swift.context* %i54, %swift.context** %i55, align 8 58 %i56 = call i8* @llvm.coro.async.resume() 59 call void @use(i8* %i56) 60 %i57 = bitcast i8* %i56 to void (%swift.context*)* 61 %i58 = getelementptr inbounds <{ %swift.context*, void (%swift.context*)*, i32 }>, <{ %swift.context*, void (%swift.context*)*, i32 }>* %i53, i32 0, i32 1 62 store void (%swift.context*)* %i57, void (%swift.context*)** %i58, align 8 63 %i59 = bitcast i8* %i52 to %swift.context* 64 %i60 = bitcast void (%swift.context*, i64, i64, %T10RR13AC*)* %i48 to i8* 65 %i61 = call { i8*, %swift.error* } (i32, i8*, i8*, ...) @llvm.coro.suspend.async.sl_p0i8p0s_swift.errorss(i32 256, i8* %i56, i8* bitcast (i8* (i8*)* @__swift_async_resume_project_context to i8*), i8* bitcast (void (i8*, %swift.context*, i64, i64, %T10RR13AC*)* @__swift_suspend_dispatch_4 to i8*), i8* %i60, %swift.context* %i59, i64 %i31, i64 0, %T10RR13AC* %arg3) 66 %i62 = extractvalue { i8*, %swift.error* } %i61, 0 67 %i63 = call i8* @__swift_async_resume_project_context(i8* %i62) 68 %i64 = bitcast i8* %i63 to %swift.context* 69 store %swift.context* %i64, %swift.context** %i, align 8 70 %i65 = extractvalue { i8*, %swift.error* } %i61, 1 71 call swiftcc void @swift_task_dealloc(i8* %i52) #1 72 br i1 %i28, label %bb126, label %bb68 73 74bb68: ; preds = %bb30 75 %i69 = call i8* @llvm.coro.async.resume() 76 call void @use(i8* %i69) 77 %i70 = load %swift.context*, %swift.context** %i, align 8 78 %i71 = call { i8* } (i32, i8*, i8*, ...) @llvm.coro.suspend.async.sl_p0i8s(i32 0, i8* %i69, i8* bitcast (i8* (i8*)* @__swift_async_resume_get_context to i8*), i8* bitcast (void (i8*, %swift.executor*, %swift.context*)* @__swift_suspend_point to i8*), i8* %i69, %swift.executor* null, %swift.context* %i70) 79 %i77 = ptrtoint %swift.bridge* %i32 to i64 80 %i78 = bitcast %T10RR13AC* %arg3 to %swift.type** 81 %i79 = load %swift.type*, %swift.type** %i78, align 8 82 %i80 = bitcast %swift.type* %i79 to void (%swift.context*, i64, i64, %T10RR13AC*)** 83 %i81 = getelementptr inbounds void (%swift.context*, i64, i64, %T10RR13AC*)*, void (%swift.context*, i64, i64, %T10RR13AC*)** %i80, i64 11 84 %i82 = load void (%swift.context*, i64, i64, %T10RR13AC*)*, void (%swift.context*, i64, i64, %T10RR13AC*)** %i81, align 8 85 %i83 = bitcast void (%swift.context*, i64, i64, %T10RR13AC*)* %i82 to %swift.async_func_pointer* 86 %i84 = getelementptr inbounds %swift.async_func_pointer, %swift.async_func_pointer* %i83, i32 0, i32 0 87 %i85 = load i32, i32* %i84, align 8 88 %i86 = sext i32 %i85 to i64 89 %i87 = ptrtoint i32* %i84 to i64 90 %i88 = add i64 %i87, %i86 91 %i89 = inttoptr i64 %i88 to i8* 92 %i90 = bitcast i8* %i89 to void (%swift.context*, i64, i64, %T10RR13AC*)* 93 %i94 = call swiftcc i8* @swift_task_alloc(i64 24) #1 94 %i98 = call i8* @llvm.coro.async.resume() 95 call void @use(i8* %i98) 96 %i102 = bitcast void (%swift.context*, i64, i64, %T10RR13AC*)* %i90 to i8* 97 %i103 = call { i8*, %swift.error* } (i32, i8*, i8*, ...) @llvm.coro.suspend.async.sl_p0i8p0s_swift.errorss(i32 256, i8* %i98, i8* bitcast (i8* (i8*)* @__swift_async_resume_project_context to i8*), i8* bitcast (void (i8*, %swift.context*, i64, i64, %T10RR13AC*)* @__swift_suspend_dispatch_4.1 to i8*), i8* %i102, %swift.context* null, i64 %i31, i64 0, %T10RR13AC* %arg3) 98 call swiftcc void @swift_task_dealloc(i8* %i94) #1 99 br label %bb126 100 101bb126: 102 %i162 = call i1 (i8*, i1, ...) @llvm.coro.end.async(i8* %i12, i1 false, void (i8*, %swift.context*, %swift.error*)* @__swift_suspend_dispatch_2, i8* bitcast (void (%swift.context*, %swift.error*)* @doIt to i8*), %swift.context* null, %swift.error* null) 103 unreachable 104} 105 106; Function Attrs: nounwind 107declare token @llvm.coro.id.async(i32, i32, i32, i8*) #1 108 109; Function Attrs: nounwind 110declare i8* @llvm.coro.begin(token, i8* writeonly) #1 111 112; Function Attrs: argmemonly nofree nosync nounwind willreturn writeonly 113declare void @llvm.memset.p0i8.i64(i8* nocapture writeonly, i8, i64, i1 immarg) #3 114 115; Function Attrs: nounwind 116declare i8* @llvm.coro.async.resume() #1 117 118; Function Attrs: noinline 119define linkonce_odr hidden i8* @__swift_async_resume_get_context(i8* %arg) #4 { 120entry: 121 ret i8* %arg 122} 123 124; Function Attrs: nounwind 125declare extern_weak swifttailcc void @swift_task_switch(%swift.context*, i8*, %swift.executor*) #1 126 127; Function Attrs: nounwind 128define internal swifttailcc void @__swift_suspend_point(i8* %arg, %swift.executor* %arg1, %swift.context* %arg2) #1 { 129entry: 130 musttail call swifttailcc void @swift_task_switch(%swift.context* swiftasync %arg2, i8* %arg, %swift.executor* %arg1) #1 131 ret void 132} 133 134; Function Attrs: nounwind 135declare { i8* } @llvm.coro.suspend.async.sl_p0i8s(i32, i8*, i8*, ...) #1 136 137; Function Attrs: nounwind 138declare i1 @llvm.coro.end.async(i8*, i1, ...) #1 139 140; Function Attrs: argmemonly nounwind 141declare extern_weak swiftcc i8* @swift_task_alloc(i64) #5 142 143; Function Attrs: nounwind readnone 144declare i8** @llvm.swift.async.context.addr() #6 145 146; Function Attrs: alwaysinline nounwind 147define linkonce_odr hidden i8* @__swift_async_resume_project_context(i8* %arg) #7 { 148entry: 149 %i = bitcast i8* %arg to i8** 150 %i1 = load i8*, i8** %i, align 8 151 %i2 = call i8** @llvm.swift.async.context.addr() 152 store i8* %i1, i8** %i2, align 8 153 ret i8* %i1 154} 155 156; Function Attrs: nounwind 157declare { i8*, %swift.error* } @llvm.coro.suspend.async.sl_p0i8p0s_swift.errorss(i32, i8*, i8*, ...) #1 158 159; Function Attrs: argmemonly nounwind 160declare extern_weak swiftcc void @swift_task_dealloc(i8*) #5 161 162; Function Attrs: nounwind 163define internal swifttailcc void @__swift_suspend_dispatch_4(i8* %arg, %swift.context* %arg1, i64 %arg2, i64 %arg3, %T10RR13AC* %arg4) #1 { 164entry: 165 %i = bitcast i8* %arg to void (%swift.context*, i64, i64, %T10RR13AC*)* 166 musttail call swifttailcc void %i(%swift.context* swiftasync %arg1, i64 %arg2, i64 %arg3, %T10RR13AC* swiftself %arg4) 167 ret void 168} 169 170declare swifttailcc void @doIt(%swift.context* swiftasync %arg1, %swift.error* swiftself %arg2) 171 172; Function Attrs: nounwind 173define internal swifttailcc void @__swift_suspend_dispatch_2(i8* %arg, %swift.context* %arg1, %swift.error* %arg2) #1 { 174entry: 175 %i = bitcast i8* %arg to void (%swift.context*, %swift.error*)* 176 musttail call swifttailcc void %i(%swift.context* swiftasync %arg1, %swift.error* swiftself %arg2) 177 ret void 178} 179 180; Function Attrs: nounwind 181define internal swifttailcc void @__swift_suspend_dispatch_4.1(i8* %arg, %swift.context* %arg1, i64 %arg2, i64 %arg3, %T10RR13AC* %arg4) #1 { 182entry: 183 %i = bitcast i8* %arg to void (%swift.context*, i64, i64, %T10RR13AC*)* 184 musttail call swifttailcc void %i(%swift.context* swiftasync %arg1, i64 %arg2, i64 %arg3, %T10RR13AC* swiftself %arg4) 185 ret void 186} 187 188attributes #0 = { "frame-pointer"="all" } 189attributes #1 = { nounwind } 190attributes #2 = { argmemonly nofree nosync nounwind willreturn } 191attributes #3 = { argmemonly nofree nosync nounwind willreturn writeonly } 192attributes #4 = { noinline "frame-pointer"="all" } 193attributes #5 = { argmemonly nounwind } 194attributes #6 = { nounwind readnone } 195attributes #7 = { alwaysinline nounwind "frame-pointer"="all" } 196