1 ; RUN: opt -winehprepare -S < %s | FileCheck %s
3 ; WinEHPrepare was crashing during phi demotion.
5 target datalayout = "e-m:w-i64:64-f80:128-n8:16:32:64-S128"
6 target triple = "x86_64-pc-windows-msvc18.0.0"
8 declare i32 @__C_specific_handler(...)
10 @str = linkonce_odr unnamed_addr constant [16 x i8] c"caught it! %lx\0A\00", align 1
12 declare void @maycrash()
13 declare void @finally(i1 %abnormal)
14 declare i32 @printf(i8* nocapture readonly, ...)
15 declare i32 @llvm.eh.typeid.for(i8*)
17 ; Function Attrs: nounwind uwtable
18 define void @doit() personality i8* bitcast (i32 (...)* @__C_specific_handler to i8*) {
20 invoke void @maycrash()
21 to label %invoke.cont unwind label %lpad.1
23 invoke.cont: ; preds = %entry
24 invoke void @maycrash()
25 to label %__try.cont unwind label %lpad
27 lpad: ; preds = %entry
28 %lp0 = landingpad { i8*, i32 }
30 catch i8* bitcast (i32 (i8*, i8*)* @"\01?filt$0@0@doit@@" to i8*)
31 %ehptr.0 = extractvalue { i8*, i32 } %lp0, 0
32 %ehsel.0 = extractvalue { i8*, i32 } %lp0, 1
33 call void @finally(i1 true)
36 lpad.1: ; preds = %invoke.cont, %lpad
37 %lp1 = landingpad { i8*, i32 }
38 catch i8* bitcast (i32 (i8*, i8*)* @"\01?filt$0@0@doit@@" to i8*)
39 %ehptr.1 = extractvalue { i8*, i32 } %lp1, 0
40 %ehsel.1 = extractvalue { i8*, i32 } %lp1, 1
44 %ehptr.2 = phi i8* [ %ehptr.0, %lpad ], [ %ehptr.1, %lpad.1 ]
45 %ehsel.2 = phi i32 [ %ehsel.0, %lpad ], [ %ehsel.1, %lpad.1 ]
46 %mysel = call i32 @llvm.eh.typeid.for(i8* bitcast (i32 (i8*, i8*)* @"\01?filt$0@0@doit@@" to i8*))
47 %matches = icmp eq i32 %ehsel.2, %mysel
48 br i1 %matches, label %__except, label %eh.resume
50 __except: ; preds = %lpad, %lpad.1
51 %t4 = ptrtoint i8* %ehptr.2 to i64
52 %t5 = trunc i64 %t4 to i32
53 %call = tail call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @str, i64 0, i64 0), i32 %t5)
56 __try.cont: ; preds = %invoke.cont, %__except
57 call void @finally(i1 false)
61 %ehvals0 = insertvalue { i8*, i32 } undef, i8* %ehptr.2, 0
62 %ehvals = insertvalue { i8*, i32 } %ehvals0, i32 %ehsel.2, 1
63 resume { i8*, i32 } %ehvals
66 define internal i32 @"\01?filt$0@0@doit@@"(i8* %exception_pointers, i8* %frame_pointer) #1 {
68 %0 = bitcast i8* %exception_pointers to { i32*, i8* }*
69 %1 = getelementptr inbounds { i32*, i8* }, { i32*, i8* }* %0, i32 0, i32 0
70 %2 = load i32*, i32** %1
71 %3 = load i32, i32* %2
72 %cmp = icmp eq i32 %3, -1073741819
73 %4 = zext i1 %cmp to i32
77 ; CHECK-LABEL: define void @doit()
78 ; CHECK: %lp0 = landingpad { i8*, i32 }
80 ; CHECK-NEXT: catch i8*
81 ; CHECK-NEXT: call i8* (...) @llvm.eh.actions({{.*}})
82 ; CHECK-NEXT: indirectbr i8* %{{[^,]*}}, [label %__except]
84 ; CHECK: %lp1 = landingpad { i8*, i32 }
85 ; CHECK-NEXT: catch i8*
86 ; CHECK-NEXT: call i8* (...) @llvm.eh.actions({{.*}})
87 ; CHECK-NEXT: indirectbr i8* %{{[^,]*}}, [label %__except]
90 ; CHECK: call i32 @llvm.eh.exceptioncode()
91 ; CHECK: call i32 (i8*, ...) @printf