|
| 1 | +; RUN: llc %s --mtriple=aarch64-pc-windows-msvc -o - | FileCheck %s |
| 2 | + |
| 3 | +; Regression test for handling MSVC C++ exceptions when there's an aligned |
| 4 | +; object on the stack. |
| 5 | + |
| 6 | +; Generated from this C++ code: |
| 7 | +; https://godbolt.org/z/cGzGfqq34 |
| 8 | +; > clang --target=aarch64-pc-windows-msvc test.cpp |
| 9 | +; ``` |
| 10 | +; // Large object: alignment seems to be important? |
| 11 | +; struct alignas(128) BigObj { |
| 12 | +; int value; |
| 13 | +; // Destructor so it's kept alive. |
| 14 | +; ~BigObj() { } |
| 15 | +; }; |
| 16 | +; |
| 17 | +; // Exception type need to be large enough to not fit in a register. |
| 18 | +; struct Error { |
| 19 | +; int value; |
| 20 | +; int padding[3]; |
| 21 | +; }; |
| 22 | +; |
| 23 | +; int main() { |
| 24 | +; BigObj bo{}; |
| 25 | +; |
| 26 | +; try { |
| 27 | +; throw Error { 42, {0, 0, 0} }; |
| 28 | +; } catch (const Error& e) { |
| 29 | +; return e.value; |
| 30 | +; } |
| 31 | +; return 0; |
| 32 | +; } |
| 33 | +; ``` |
| 34 | + |
| 35 | +; CHECK-LABEL: main: |
| 36 | +; CHECK: sub x[[SPTMP:[0-9]+]], sp, #336 |
| 37 | +; CHECK: and sp, x[[SPTMP]], #0xffffffffffffff80 |
| 38 | +; CHECK: mov x[[FP:[0-9]+]], sp |
| 39 | +; CHECK: str wzr, [x[[FP]], #332] |
| 40 | + |
| 41 | +; CHECK-LABEL: "?catch$3@?0?main@4HA": |
| 42 | +; CHECK: str w8, [x[[FP]], #332] |
| 43 | +; CHECK-NEXT: .seh_startepilogue |
| 44 | +; CHECK: ret |
| 45 | + |
| 46 | +; CHECK-LABEL: $cppxdata$main: |
| 47 | +; CHECK: .word -16 // UnwindHelp |
| 48 | +; CHECK-LABEL: $handlerMap$0$main: |
| 49 | +; CHECK-NEXT: .word 8 // Adjectives |
| 50 | +; CHECK-NEXT: .word "??_R0?AUError@@@8"@IMGREL // Type |
| 51 | +; CHECK-NEXT: .word -8 // CatchObjOffset |
| 52 | +; CHECK-NEXT: .word "?catch$3@?0?main@4HA"@IMGREL // Handler |
| 53 | + |
| 54 | +%rtti.TypeDescriptor11 = type { ptr, ptr, [12 x i8] } |
| 55 | +%eh.CatchableType = type { i32, i32, i32, i32, i32, i32, i32 } |
| 56 | +%eh.CatchableTypeArray.1 = type { i32, [1 x i32] } |
| 57 | +%eh.ThrowInfo = type { i32, i32, i32, i32 } |
| 58 | +%struct.BigObj = type { i32, [124 x i8] } |
| 59 | +%struct.Error = type { i32, [3 x i32] } |
| 60 | + |
| 61 | +$"??1BigObj@@QEAA@XZ" = comdat any |
| 62 | + |
| 63 | +$"??_R0?AUError@@@8" = comdat any |
| 64 | + |
| 65 | +$"_CT??_R0?AUError@@@816" = comdat any |
| 66 | + |
| 67 | +$"_CTA1?AUError@@" = comdat any |
| 68 | + |
| 69 | +$"_TI1?AUError@@" = comdat any |
| 70 | + |
| 71 | +@"??_7type_info@@6B@" = external constant ptr |
| 72 | +@"??_R0?AUError@@@8" = linkonce_odr global %rtti.TypeDescriptor11 { ptr @"??_7type_info@@6B@", ptr null, [12 x i8] c".?AUError@@\00" }, comdat |
| 73 | +@__ImageBase = external dso_local constant i8 |
| 74 | +@"_CT??_R0?AUError@@@816" = linkonce_odr unnamed_addr constant %eh.CatchableType { i32 0, i32 trunc (i64 sub nuw nsw (i64 ptrtoint (ptr @"??_R0?AUError@@@8" to i64), i64 ptrtoint (ptr @__ImageBase to i64)) to i32), i32 0, i32 -1, i32 0, i32 16, i32 0 }, section ".xdata", comdat |
| 75 | +@"_CTA1?AUError@@" = linkonce_odr unnamed_addr constant %eh.CatchableTypeArray.1 { i32 1, [1 x i32] [i32 trunc (i64 sub nuw nsw (i64 ptrtoint (ptr @"_CT??_R0?AUError@@@816" to i64), i64 ptrtoint (ptr @__ImageBase to i64)) to i32)] }, section ".xdata", comdat |
| 76 | +@"_TI1?AUError@@" = linkonce_odr unnamed_addr constant %eh.ThrowInfo { i32 0, i32 0, i32 0, i32 trunc (i64 sub nuw nsw (i64 ptrtoint (ptr @"_CTA1?AUError@@" to i64), i64 ptrtoint (ptr @__ImageBase to i64)) to i32) }, section ".xdata", comdat |
| 77 | + |
| 78 | +define dso_local noundef i32 @main() personality ptr @__CxxFrameHandler3 { |
| 79 | +entry: |
| 80 | + %retval = alloca i32, align 4 |
| 81 | + %bo = alloca %struct.BigObj, align 128 |
| 82 | + %tmp = alloca %struct.Error, align 4 |
| 83 | + %e = alloca ptr, align 8 |
| 84 | + %cleanup.dest.slot = alloca i32, align 4 |
| 85 | + store i32 0, ptr %retval, align 4 |
| 86 | + call void @llvm.memset.p0.i64(ptr align 128 %bo, i8 0, i64 128, i1 false) |
| 87 | + %value = getelementptr inbounds nuw %struct.BigObj, ptr %bo, i32 0, i32 0 |
| 88 | + %value1 = getelementptr inbounds nuw %struct.Error, ptr %tmp, i32 0, i32 0 |
| 89 | + store i32 42, ptr %value1, align 4 |
| 90 | + %padding = getelementptr inbounds nuw %struct.Error, ptr %tmp, i32 0, i32 1 |
| 91 | + store i32 0, ptr %padding, align 4 |
| 92 | + %arrayinit.element = getelementptr inbounds i32, ptr %padding, i64 1 |
| 93 | + store i32 0, ptr %arrayinit.element, align 4 |
| 94 | + %arrayinit.element2 = getelementptr inbounds i32, ptr %padding, i64 2 |
| 95 | + store i32 0, ptr %arrayinit.element2, align 4 |
| 96 | + invoke void @_CxxThrowException(ptr %tmp, ptr @"_TI1?AUError@@") #3 |
| 97 | + to label %unreachable unwind label %catch.dispatch |
| 98 | + |
| 99 | +catch.dispatch: |
| 100 | + %0 = catchswitch within none [label %catch] unwind label %ehcleanup |
| 101 | + |
| 102 | +catch: |
| 103 | + %1 = catchpad within %0 [ptr @"??_R0?AUError@@@8", i32 8, ptr %e] |
| 104 | + %2 = load ptr, ptr %e, align 8 |
| 105 | + %value3 = getelementptr inbounds nuw %struct.Error, ptr %2, i32 0, i32 0 |
| 106 | + %3 = load i32, ptr %value3, align 4 |
| 107 | + store i32 %3, ptr %retval, align 4 |
| 108 | + store i32 1, ptr %cleanup.dest.slot, align 4 |
| 109 | + catchret from %1 to label %catchret.dest |
| 110 | + |
| 111 | +catchret.dest: |
| 112 | + br label %cleanup |
| 113 | + |
| 114 | +try.cont: |
| 115 | + store i32 0, ptr %retval, align 4 |
| 116 | + store i32 1, ptr %cleanup.dest.slot, align 4 |
| 117 | + br label %cleanup |
| 118 | + |
| 119 | +cleanup: |
| 120 | + call void @"??1BigObj@@QEAA@XZ"(ptr noundef nonnull align 128 dereferenceable(4) %bo) #4 |
| 121 | + %4 = load i32, ptr %retval, align 4 |
| 122 | + ret i32 %4 |
| 123 | + |
| 124 | +ehcleanup: |
| 125 | + %5 = cleanuppad within none [] |
| 126 | + call void @"??1BigObj@@QEAA@XZ"(ptr noundef nonnull align 128 dereferenceable(4) %bo) [ "funclet"(token %5) ] |
| 127 | + cleanupret from %5 unwind to caller |
| 128 | + |
| 129 | +unreachable: |
| 130 | + unreachable |
| 131 | +} |
| 132 | + |
| 133 | +declare void @llvm.memset.p0.i64(ptr writeonly captures(none), i8, i64, i1 immarg) #1 |
| 134 | + |
| 135 | +declare dso_local void @_CxxThrowException(ptr, ptr) |
| 136 | + |
| 137 | +declare dso_local i32 @__CxxFrameHandler3(...) |
| 138 | + |
| 139 | +define linkonce_odr dso_local void @"??1BigObj@@QEAA@XZ"(ptr noundef nonnull align 128 dereferenceable(4) %this) unnamed_addr comdat { |
| 140 | +entry: |
| 141 | + %this.addr = alloca ptr, align 8 |
| 142 | + store ptr %this, ptr %this.addr, align 8 |
| 143 | + %this1 = load ptr, ptr %this.addr, align 8 |
| 144 | + ret void |
| 145 | +} |
0 commit comments