[llvm] [CoroSplit] Fix infinite loop in CoroSplit (PR #185599)
Felipe de Azevedo Piovezan via llvm-commits
llvm-commits at lists.llvm.org
Wed Mar 11 01:39:07 PDT 2026
================
@@ -0,0 +1,62 @@
+; RUN: opt < %s -passes='cgscc(coro-split),simplifycfg,early-cse' -S | FileCheck %s
+
+@"coroutineTwc" = global <{ i32, i32, i64 }> <{ i32 trunc (i64 sub (i64 ptrtoint (ptr @"coroutine" to i64), i64 ptrtoint (ptr @"coroutineTwc" to i64)) to i32), i32 0, i64 51979 }>, align 8
+
+; This test ensures CoroSplit will not loop infinitely in the presence of an
+; infinite loop in the IR, but it will still split the coroutine.
+;CHECK: define {{.*}}@coroutine(
+;CHECK: define {{.*}}@coroutine.resume
+define swiftcc { ptr, ptr } @coroutine(ptr noalias %0, ptr %1, ptr swiftself %2) #0 !dbg !39 {
+entry:
+ %3 = call token @llvm.coro.id.retcon.once(i32 -1, i32 16, ptr %0, ptr @"$s4test1SVSiIetMIlYl_TC", ptr @_swift_coro_alloc, ptr @_swift_coro_dealloc), !dbg !48
+ %4 = call ptr @llvm.coro.begin(token %3, ptr null), !dbg !48
+ call swiftcc void @"$s4test6FINISHyyF"(), !dbg !50
+ %.member_int = getelementptr inbounds nuw <{ <{ i64 }> }>, ptr %2, i32 0, i32 0, !dbg !51
+ %5 = call ptr (...) @llvm.coro.suspend.retcon.p0(ptr %.member_int), !dbg !52 ; [debug line = 11:7]
+ br label %loop
+
+loop:
+ br label %loop
+
+coro.end:
+ call void @llvm.coro.end(ptr %4, i1 false, token none), !dbg !54
+ unreachable, !dbg !54
+}
+
+declare swiftcc void @"$s4test6FINISHyyF"()
+declare swiftcc ptr @_swift_coro_alloc(i64) #3
+declare swiftcc void @_swift_coro_dealloc(ptr) #3
+declare swiftcc ptr @_swift_coro_alloc_frame(ptr, ptr, i64, i64) #3
+declare swiftcc void @_swift_coro_dealloc_frame(ptr, ptr, ptr) #3
+declare swiftcc void @"$s4test1SVSiIetMIlYl_TC"(ptr noalias, ptr)
+
+attributes #0 = { noinline presplitcoroutine }
+attributes #3 = { noinline nounwind }
+
+!llvm.module.flags = !{!7, !8, !9, !10, !11}
+!llvm.dbg.cu = !{!17}
+
+!7 = !{i32 7, !"Dwarf Version", i32 5}
+!8 = !{i32 2, !"Debug Info Version", i32 3}
+!9 = !{i32 1, !"wchar_size", i32 4}
+!10 = !{i32 8, !"PIC Level", i32 2}
+!11 = !{i32 7, !"uwtable", i32 1}
+!17 = distinct !DICompileUnit(language: DW_LANG_Swift, file: !18, producer: "Swift", isOptimized: false, emissionKind: FullDebug)
----------------
felipepiovezan wrote:
Yes, otherwise we won't go into the debug info code paths
https://github.com/llvm/llvm-project/pull/185599
More information about the llvm-commits
mailing list