[SEH] Update SEH codegen tests to use the new IR
[oota-llvm.git] / test / CodeGen / X86 / seh-safe-div-win32.ll
index ab58a4b99ca2f7a2fd525d426d97959f3d9fd4e4..d17f2217ca2fc171d2432eb85a096ba2d7694d98 100644 (file)
 @str1 = internal constant [27 x i8] c"EXCEPTION_ACCESS_VIOLATION\00"
 @str2 = internal constant [29 x i8] c"EXCEPTION_INT_DIVIDE_BY_ZERO\00"
 
-define i32 @safe_div(i32* %n, i32* %d) {
+define i32 @safe_div(i32* %n, i32* %d) personality i8* bitcast (i32 (...)* @_except_handler3 to i8*) {
 entry:
   %r = alloca i32, align 4
   store i32 42, i32* %r
   invoke void @try_body(i32* %r, i32* %n, i32* %d)
-          to label %__try.cont unwind label %lpad
-
-lpad:
-  %vals = landingpad { i8*, i32 } personality i8* bitcast (i32 (...)* @_except_handler3 to i8*)
-          catch i8* bitcast (i32 ()* @safe_div_filt0 to i8*)
-          catch i8* bitcast (i32 ()* @safe_div_filt1 to i8*)
-  %ehptr = extractvalue { i8*, i32 } %vals, 0
-  %sel = extractvalue { i8*, i32 } %vals, 1
-  %filt0_val = call i32 @llvm.eh.typeid.for(i8* bitcast (i32 ()* @safe_div_filt0 to i8*))
-  %is_filt0 = icmp eq i32 %sel, %filt0_val
-  br i1 %is_filt0, label %handler0, label %eh.dispatch1
-
-eh.dispatch1:
-  %filt1_val = call i32 @llvm.eh.typeid.for(i8* bitcast (i32 ()* @safe_div_filt1 to i8*))
-  %is_filt1 = icmp eq i32 %sel, %filt1_val
-  br i1 %is_filt1, label %handler1, label %eh.resume
+          to label %__try.cont unwind label %lpad0
+
+lpad0:
+  %p0 = catchpad [i8* bitcast (i32 ()* @safe_div_filt0 to i8*)]
+          to label %handler0 unwind label %endpad0
 
 handler0:
   call void @puts(i8* getelementptr ([27 x i8], [27 x i8]* @str1, i32 0, i32 0))
   store i32 -1, i32* %r, align 4
-  br label %__try.cont
+  catchret %p0 to label %__try.cont
+
+endpad0:
+  catchendpad unwind label %lpad1
+
+lpad1:
+  %p1 = catchpad [i8* bitcast (i32 ()* @safe_div_filt1 to i8*)]
+          to label %handler1 unwind label %endpad1
 
 handler1:
   call void @puts(i8* getelementptr ([29 x i8], [29 x i8]* @str2, i32 0, i32 0))
   store i32 -2, i32* %r, align 4
-  br label %__try.cont
+  catchret %p1 to label %__try.cont
 
-eh.resume:
-  resume { i8*, i32 } %vals
+endpad1:
+  catchendpad unwind to caller
 
 __try.cont:
   %safe_ret = load i32, i32* %r, align 4
@@ -75,15 +71,13 @@ __try.cont:
 
 ; Landing pad code
 
-; CHECK: [[handler0:Ltmp[0-9]+]]: # Block address taken
-; CHECK: # %handler0
+; CHECK: [[lpad1:LBB0_[0-9]+]]: # %lpad1
 ;      Restore SP
 ; CHECK: movl {{.*}}(%ebp), %esp
 ; CHECK: calll _puts
 ; CHECK: jmp [[cont_bb]]
 
-; CHECK: [[handler1:Ltmp[0-9]+]]: # Block address taken
-; CHECK: # %handler1
+; CHECK: [[lpad0:LBB0_[0-9]+]]: # %lpad0
 ;      Restore SP
 ; CHECK: movl {{.*}}(%ebp), %esp
 ; CHECK: calll _puts
@@ -92,11 +86,11 @@ __try.cont:
 ; CHECK: .section .xdata,"dr"
 ; CHECK: L__ehtable$safe_div:
 ; CHECK-NEXT: .long -1
-; CHECK-NEXT: .long _safe_div_filt0
-; CHECK-NEXT: .long [[handler0]]
-; CHECK-NEXT: .long 0
 ; CHECK-NEXT: .long _safe_div_filt1
-; CHECK-NEXT: .long [[handler1]]
+; CHECK-NEXT: .long [[lpad1]]
+; CHECK-NEXT: .long 0
+; CHECK-NEXT: .long _safe_div_filt0
+; CHECK-NEXT: .long [[lpad0]]
 
 define void @try_body(i32* %r, i32* %n, i32* %d) {
 entry:
@@ -122,27 +116,30 @@ entry:
 ;     ...
 ;   } EXCEPTION_RECORD;
 
-; FIXME: Use llvm.eh.exceptioninfo for this.
-declare i32 @safe_div_filt0()
-declare i32 @safe_div_filt1()
-; define i32 @safe_div_filt0() {
-;   %eh_ptrs_c = bitcast i8* %eh_ptrs to i32**
-;   %eh_rec = load i32*, i32** %eh_ptrs_c
-;   %eh_code = load i32, i32* %eh_rec
-;   ; EXCEPTION_ACCESS_VIOLATION = 0xC0000005
-;   %cmp = icmp eq i32 %eh_code, 3221225477
-;   %filt.res = zext i1 %cmp to i32
-;   ret i32 %filt.res
-; }
-; define i32 @safe_div_filt1() {
-;   %eh_ptrs_c = bitcast i8* %eh_ptrs to i32**
-;   %eh_rec = load i32*, i32** %eh_ptrs_c
-;   %eh_code = load i32, i32* %eh_rec
-;   ; EXCEPTION_INT_DIVIDE_BY_ZERO = 0xC0000094
-;   %cmp = icmp eq i32 %eh_code, 3221225620
-;   %filt.res = zext i1 %cmp to i32
-;   ret i32 %filt.res
-; }
+define i32 @safe_div_filt0() {
+  %ebp = call i8* @llvm.frameaddress(i32 1)
+  %eh_ptrs.addr.i8 = getelementptr inbounds i8, i8* %ebp, i32 -20
+  %eh_ptrs.addr = bitcast i8* %eh_ptrs.addr.i8 to i32***
+  %eh_ptrs = load i32**, i32*** %eh_ptrs.addr
+  %eh_rec = load i32*, i32** %eh_ptrs
+  %eh_code = load i32, i32* %eh_rec
+  ; EXCEPTION_ACCESS_VIOLATION = 0xC0000005
+  %cmp = icmp eq i32 %eh_code, 3221225477
+  %filt.res = zext i1 %cmp to i32
+  ret i32 %filt.res
+}
+define i32 @safe_div_filt1() {
+  %ebp = call i8* @llvm.frameaddress(i32 1)
+  %eh_ptrs.addr.i8 = getelementptr inbounds i8, i8* %ebp, i32 -20
+  %eh_ptrs.addr = bitcast i8* %eh_ptrs.addr.i8 to i32***
+  %eh_ptrs = load i32**, i32*** %eh_ptrs.addr
+  %eh_rec = load i32*, i32** %eh_ptrs
+  %eh_code = load i32, i32* %eh_rec
+  ; EXCEPTION_INT_DIVIDE_BY_ZERO = 0xC0000094
+  %cmp = icmp eq i32 %eh_code, 3221225620
+  %filt.res = zext i1 %cmp to i32
+  ret i32 %filt.res
+}
 
 @str_result = internal constant [21 x i8] c"safe_div result: %d\0A\00"
 
@@ -170,3 +167,4 @@ declare i32 @llvm.eh.typeid.for(i8*) readnone nounwind
 declare void @puts(i8*)
 declare void @printf(i8*, ...)
 declare void @abort()
+declare i8* @llvm.frameaddress(i32)