llvm.org GIT mirror llvm / e233704
[WinEH] Insert the EH code load before the block terminator The previous code put the load after the terminator, leading to invalid IR and downstream crashes. This caused http://crbug.com/506446. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@241509 91177308-0d34-0410-b5e6-96231b3b80d8 Reid Kleckner 5 years ago
2 changed file(s) with 67 addition(s) and 1 deletion(s). Raw diff Collapse all Expand all
832832 LoadInst *LI;
833833 if (auto *Phi = dyn_cast(I))
834834 LI = new LoadInst(SEHExceptionCodeSlot, "sehcode", false,
835 Phi->getIncomingBlock(*U));
835 Phi->getIncomingBlock(*U)->getTerminator());
836836 else
837837 LI = new LoadInst(SEHExceptionCodeSlot, "sehcode", false, I);
838838 U->set(LI);
0 ; RUN: opt -winehprepare -S < %s | FileCheck %s
1
2 ; WinEHPrepare was crashing during phi demotion.
3
4 target datalayout = "e-m:w-i64:64-f80:128-n8:16:32:64-S128"
5 target triple = "x86_64-pc-windows-msvc18.0.0"
6
7 declare i32 @__C_specific_handler(...)
8
9 @str = linkonce_odr unnamed_addr constant [16 x i8] c"caught it! %lx\0A\00", align 1
10
11 ; Function Attrs: nounwind uwtable
12 declare void @maycrash()
13
14 ; Function Attrs: nounwind
15 declare i32 @printf(i8* nocapture readonly, ...)
16
17 ; Function Attrs: nounwind uwtable
18 define void @doit() personality i8* bitcast (i32 (...)* @__C_specific_handler to i8*) {
19 entry:
20 invoke void @maycrash()
21 to label %invoke.cont unwind label %lpad
22
23 invoke.cont: ; preds = %entry
24 invoke void @maycrash()
25 to label %__try.cont unwind label %lpad.1
26
27 lpad: ; preds = %entry
28 %0 = landingpad { i8*, i32 }
29 catch i8* null
30 %1 = extractvalue { i8*, i32 } %0, 0
31 br label %__except
32
33 lpad.1: ; preds = %invoke.cont, %lpad
34 %2 = landingpad { i8*, i32 }
35 catch i8* null
36 %3 = extractvalue { i8*, i32 } %2, 0
37 br label %__except
38
39 __except: ; preds = %lpad, %lpad.1
40 %exn.slot.0 = phi i8* [ %3, %lpad.1 ], [ %1, %lpad ]
41 %4 = ptrtoint i8* %exn.slot.0 to i64
42 %5 = trunc i64 %4 to i32
43 %call = tail call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @str, i64 0, i64 0), i32 %5)
44 br label %__try.cont
45
46 __try.cont: ; preds = %invoke.cont, %__except
47 ret void
48 }
49
50 ; CHECK-LABEL: define void @doit()
51 ; CHECK: landingpad
52 ; CHECK: indirectbr i8* %{{[^,]*}}, [label %[[except_split1:.*]]]
53 ; CHECK: [[except_split1]]:
54 ; CHECK: call i32 @llvm.eh.exceptioncode()
55 ; CHECK: br label %__except
56 ;
57 ; CHECK: landingpad
58 ; CHECK: indirectbr i8* %{{[^,]*}}, [label %[[except_split2:.*]]]
59 ; CHECK: [[except_split2]]:
60 ; CHECK: call i32 @llvm.eh.exceptioncode()
61 ; CHECK: br label %__except
62 ;
63 ; CHECK: __except:
64 ; CHECK: phi
65 ; CHECK: call i32 (i8*, ...) @printf