Reid Kleckner | b8fd162 | 2015-11-06 17:06:38 +0000 | [diff] [blame^] | 1 | ; RUN: llc < %s | FileCheck %s |
| 2 | |
| 3 | ; Based on this code: |
| 4 | ; |
| 5 | ; extern "C" int array[4]; |
| 6 | ; extern "C" void global_array(int idx1, int idx2, int idx3) { |
| 7 | ; try { |
| 8 | ; array[idx1] = 111; |
| 9 | ; throw; |
| 10 | ; } catch (...) { |
| 11 | ; array[idx2] = 222; |
| 12 | ; } |
| 13 | ; array[idx3] = 333; |
| 14 | ; } |
| 15 | ; extern "C" __declspec(dllimport) int imported; |
| 16 | ; extern "C" void access_imported() { |
| 17 | ; try { |
| 18 | ; imported = 111; |
| 19 | ; throw; |
| 20 | ; } catch (...) { |
| 21 | ; imported = 222; |
| 22 | ; } |
| 23 | ; imported = 333; |
| 24 | ; } |
| 25 | |
| 26 | target datalayout = "e-m:w-i64:64-f80:128-n8:16:32:64-S128" |
| 27 | target triple = "x86_64-pc-windows-msvc18.0.0" |
| 28 | |
| 29 | %eh.ThrowInfo = type { i32, i32, i32, i32 } |
| 30 | |
| 31 | @array = external global [4 x i32], align 16 |
| 32 | @imported = external dllimport global i32, align 4 |
| 33 | |
| 34 | ; Function Attrs: uwtable |
| 35 | define void @global_array(i32 %idx1, i32 %idx2, i32 %idx3) #0 personality i8* bitcast (i32 (...)* @__CxxFrameHandler3 to i8*) { |
| 36 | entry: |
| 37 | %idxprom = sext i32 %idx1 to i64 |
| 38 | %arrayidx = getelementptr inbounds [4 x i32], [4 x i32]* @array, i64 0, i64 %idxprom |
| 39 | store i32 111, i32* %arrayidx, align 4, !tbaa !2 |
| 40 | invoke void @_CxxThrowException(i8* null, %eh.ThrowInfo* null) #1 |
| 41 | to label %unreachable unwind label %catch.dispatch |
| 42 | |
| 43 | catch.dispatch: ; preds = %entry |
| 44 | %0 = catchpad [i8* null, i32 64, i8* null] |
| 45 | to label %catch unwind label %catchendblock |
| 46 | |
| 47 | catch: ; preds = %catch.dispatch |
| 48 | %idxprom1 = sext i32 %idx2 to i64 |
| 49 | %arrayidx2 = getelementptr inbounds [4 x i32], [4 x i32]* @array, i64 0, i64 %idxprom1 |
| 50 | store i32 222, i32* %arrayidx2, align 4, !tbaa !2 |
| 51 | catchret %0 to label %try.cont |
| 52 | |
| 53 | try.cont: ; preds = %catch |
| 54 | %idxprom3 = sext i32 %idx3 to i64 |
| 55 | %arrayidx4 = getelementptr inbounds [4 x i32], [4 x i32]* @array, i64 0, i64 %idxprom3 |
| 56 | store i32 333, i32* %arrayidx4, align 4, !tbaa !2 |
| 57 | ret void |
| 58 | |
| 59 | catchendblock: ; preds = %catch.dispatch |
| 60 | catchendpad unwind to caller |
| 61 | |
| 62 | unreachable: ; preds = %entry |
| 63 | unreachable |
| 64 | } |
| 65 | |
| 66 | ; CHECK-LABEL: global_array: # @global_array |
| 67 | ; CHECK: pushq %rbp |
| 68 | ; First array access |
| 69 | ; CHECK: movslq %ecx, %[[idx:[^ ]*]] |
| 70 | ; CHECK: leaq array(%rip), %[[base:[^ ]*]] |
| 71 | ; CHECK: movl $111, (%[[base]],%[[idx]],4) |
| 72 | ; Might throw an exception and return to below... |
| 73 | ; CHECK: callq _CxxThrowException |
| 74 | ; Third array access must remat the address of array |
| 75 | ; CHECK: movslq {{.*}}, %[[idx:[^ ]*]] |
| 76 | ; CHECK: leaq array(%rip), %[[base:[^ ]*]] |
| 77 | ; CHECK: movl $333, (%[[base]],%[[idx]],4) |
| 78 | ; CHECK: popq %rbp |
| 79 | ; CHECK: retq |
| 80 | |
| 81 | ; CHECK: "?catch$2@?0?global_array@4HA": |
| 82 | ; CHECK: pushq %rbp |
| 83 | ; CHECK: movslq {{.*}}, %[[idx:[^ ]*]] |
| 84 | ; CHECK: leaq array(%rip), %[[base:[^ ]*]] |
| 85 | ; CHECK: movl $222, (%[[base]],%[[idx]],4) |
| 86 | ; CHECK: popq %rbp |
| 87 | ; CHECK: retq # CATCHRET |
| 88 | |
| 89 | declare void @_CxxThrowException(i8*, %eh.ThrowInfo*) |
| 90 | |
| 91 | declare i32 @__CxxFrameHandler3(...) |
| 92 | |
| 93 | ; Function Attrs: uwtable |
| 94 | define void @access_imported() #0 personality i8* bitcast (i32 (...)* @__CxxFrameHandler3 to i8*) { |
| 95 | entry: |
| 96 | store i32 111, i32* @imported, align 4, !tbaa !2 |
| 97 | invoke void @_CxxThrowException(i8* null, %eh.ThrowInfo* null) #1 |
| 98 | to label %unreachable unwind label %catch.dispatch |
| 99 | |
| 100 | catch.dispatch: ; preds = %entry |
| 101 | %0 = catchpad [i8* null, i32 64, i8* null] |
| 102 | to label %catch unwind label %catchendblock |
| 103 | |
| 104 | catch: ; preds = %catch.dispatch |
| 105 | store i32 222, i32* @imported, align 4, !tbaa !2 |
| 106 | catchret %0 to label %try.cont |
| 107 | |
| 108 | try.cont: ; preds = %catch |
| 109 | store i32 333, i32* @imported, align 4, !tbaa !2 |
| 110 | ret void |
| 111 | |
| 112 | catchendblock: ; preds = %catch.dispatch |
| 113 | catchendpad unwind to caller |
| 114 | |
| 115 | unreachable: ; preds = %entry |
| 116 | unreachable |
| 117 | } |
| 118 | |
| 119 | ; CHECK-LABEL: access_imported: # @access_imported |
| 120 | ; CHECK: pushq %rbp |
| 121 | ; CHECK: movq __imp_imported(%rip), %[[base:[^ ]*]] |
| 122 | ; CHECK: movl $111, (%[[base]]) |
| 123 | ; Might throw an exception and return to below... |
| 124 | ; CHECK: callq _CxxThrowException |
| 125 | ; Third access must reload the address of imported |
| 126 | ; CHECK: movq __imp_imported(%rip), %[[base:[^ ]*]] |
| 127 | ; CHECK: movl $333, (%[[base]]) |
| 128 | ; CHECK: popq %rbp |
| 129 | ; CHECK: retq |
| 130 | |
| 131 | ; CHECK: "?catch$2@?0?access_imported@4HA": |
| 132 | ; CHECK: pushq %rbp |
| 133 | ; CHECK: movq __imp_imported(%rip), %[[base:[^ ]*]] |
| 134 | ; CHECK: movl $222, (%[[base]]) |
| 135 | ; CHECK: popq %rbp |
| 136 | ; CHECK: retq # CATCHRET |
| 137 | |
| 138 | |
| 139 | attributes #0 = { uwtable "disable-tail-calls"="false" "less-precise-fpmad"="false" "no-frame-pointer-elim"="false" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+fxsr,+mmx,+sse,+sse2" "unsafe-fp-math"="false" "use-soft-float"="false" } |
| 140 | attributes #1 = { noreturn } |
| 141 | |
| 142 | !llvm.module.flags = !{!0} |
| 143 | !llvm.ident = !{!1} |
| 144 | |
| 145 | !0 = !{i32 1, !"PIC Level", i32 2} |
| 146 | !1 = !{!"clang version 3.8.0 "} |
| 147 | !2 = !{!3, !3, i64 0} |
| 148 | !3 = !{!"int", !4, i64 0} |
| 149 | !4 = !{!"omnipotent char", !5, i64 0} |
| 150 | !5 = !{!"Simple C/C++ TBAA"} |