|
| 1 | +; RUN: llc -mtriple=aarch64-windows %s -o - | FileCheck %s |
| 2 | + |
| 3 | +; This test verifies that functions requiring Windows CFI that have minimal |
| 4 | +; or no prologue instructions still emit proper SEH directives, specifically |
| 5 | +; ensuring .seh_endprologue is emitted before .seh_startepilogue. |
| 6 | +; |
| 7 | +; This reproduces the issue where Swift async functions with swifttailcc |
| 8 | +; calling convention would fail with: |
| 9 | +; "error: starting epilogue (.seh_startepilogue) before prologue has ended (.seh_endprologue)" |
| 10 | + |
| 11 | +; Test 1: Swift-style tail call function with minimal prologue |
| 12 | +define swifttailcc void @test_swifttailcc_minimal(ptr %async_ctx, ptr %arg1, ptr %arg2) { |
| 13 | +; CHECK-LABEL: test_swifttailcc_minimal: |
| 14 | +; CHECK-NOT: .seh_proc test_swifttailcc_minimal |
| 15 | +; CHECK-NOT: .seh_endprologue |
| 16 | +; CHECK-NOT: .seh_startepilogue |
| 17 | +; CHECK-NOT: .seh_endepilogue |
| 18 | +; CHECK-NOT: .seh_endproc |
| 19 | +entry: |
| 20 | + %ptr1 = getelementptr inbounds i8, ptr %async_ctx, i64 16 |
| 21 | + %ptr2 = getelementptr inbounds i8, ptr %async_ctx, i64 24 |
| 22 | + store ptr %arg1, ptr %ptr1, align 8 |
| 23 | + store ptr %arg2, ptr %ptr2, align 8 |
| 24 | + musttail call swifttailcc void @external_swift_function(ptr %async_ctx, ptr %arg1) |
| 25 | + ret void |
| 26 | +} |
| 27 | + |
| 28 | +; Test 2: Function similar to the original failing case |
| 29 | +define linkonce_odr hidden swifttailcc void @test_linkonce_swifttailcc(ptr swiftasync %async_ctx, ptr %arg1, ptr noalias dereferenceable(40) %arg2, ptr %arg3, i64 %value, ptr %arg4, ptr %arg5, ptr %arg6, i1 %flag, ptr %arg7, ptr noalias dereferenceable(40) %arg8) { |
| 30 | +; CHECK-LABEL: test_linkonce_swifttailcc: |
| 31 | +; CHECK-NEXT: .seh_proc |
| 32 | +; CHECK: .seh_endprologue |
| 33 | +; CHECK: .seh_startepilogue |
| 34 | +; CHECK: .seh_endepilogue |
| 35 | +; CHECK: .seh_endproc |
| 36 | +entry: |
| 37 | + %frame_ptr = getelementptr inbounds nuw i8, ptr %async_ctx, i64 16 |
| 38 | + %ctx1 = getelementptr inbounds nuw i8, ptr %async_ctx, i64 400 |
| 39 | + %ctx2 = getelementptr inbounds nuw i8, ptr %async_ctx, i64 1168 |
| 40 | + %spill1 = getelementptr inbounds nuw i8, ptr %async_ctx, i64 2392 |
| 41 | + store ptr %arg8, ptr %spill1, align 8 |
| 42 | + %spill2 = getelementptr inbounds nuw i8, ptr %async_ctx, i64 2384 |
| 43 | + store ptr %arg7, ptr %spill2, align 8 |
| 44 | + %spill3 = getelementptr inbounds nuw i8, ptr %async_ctx, i64 2225 |
| 45 | + store i1 %flag, ptr %spill3, align 1 |
| 46 | + %spill4 = getelementptr inbounds nuw i8, ptr %async_ctx, i64 2376 |
| 47 | + store ptr %arg6, ptr %spill4, align 8 |
| 48 | + musttail call swifttailcc void @external_swift_continuation(ptr swiftasync %async_ctx, i64 0, i64 0) |
| 49 | + ret void |
| 50 | +} |
| 51 | + |
| 52 | +declare swifttailcc void @external_swift_function(ptr, ptr) |
| 53 | +declare swifttailcc void @external_swift_continuation(ptr swiftasync, i64, i64) |
0 commit comments