llvm.org GIT mirror llvm / d1807ff
[WinEH] Replace more lpad value uses with undef We were asserting on code like this: extern "C" unsigned long _exception_code(); void might_crash(unsigned long); void foo() { __try { might_crash(0); } __except(1) { might_crash(_exception_code()); } } Gtest and many other libraries get the exception code from the __except block. What's supposed to happen here is that EAX is live into the __except block, and it contains the exception code. Eventually we'll represent that as a use of the landingpad ehptr value, but for now we can replace it with undef. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@235649 91177308-0d34-0410-b5e6-96231b3b80d8 Reid Kleckner 5 years ago
2 changed file(s) with 87 addition(s) and 9 deletion(s). Raw diff Collapse all Expand all
695695 Invoke->setUnwindDest(NewLPadBB);
696696 }
697697
698 // If anyone is still using the old landingpad value, just give them undef
699 // instead. The eh pointer and selector values are not real.
700 LPad->replaceAllUsesWith(UndefValue::get(LPad->getType()));
701
702698 // Replace the mapping of any nested landing pad that previously mapped
703699 // to this landing pad with a referenced to the cloned version.
704700 for (auto &LPadPair : NestedLPtoOriginalLP) {
708704 }
709705 }
710706
711 // Replace uses of the old lpad in phis with this block and delete the old
712 // block.
713 LPadBB->replaceSuccessorsPhiUsesWith(NewLPadBB);
714 LPadBB->getTerminator()->eraseFromParent();
715 new UnreachableInst(LPadBB->getContext(), LPadBB);
707 // Replace all extracted values with undef and ultimately replace the
708 // landingpad with undef.
709 // FIXME: This doesn't handle SEH GetExceptionCode(). For now, we just give
710 // out undef until we figure out the codegen support.
711 SmallVector Extracts;
712 for (User *U : LPad->users()) {
713 auto *E = dyn_cast(U);
714 if (!E)
715 continue;
716 assert(E->getNumIndices() == 1 &&
717 "Unexpected operation: extracting both landing pad values");
718 unsigned Idx = E->getIndices()[0];
719 assert(Idx == 0 || Idx == 1);
720 Extracts.push_back(E);
721 }
722 for (Instruction *E : Extracts) {
723 E->replaceAllUsesWith(UndefValue::get(E->getType()));
724 E->eraseFromParent();
725 }
726 LPad->replaceAllUsesWith(UndefValue::get(LPad->getType()));
716727
717728 // Add a call to describe the actions for this landing pad.
718729 std::vector ActionArgs;
0 ; RUN: opt -S -winehprepare -sehprepare < %s | FileCheck %s
1
2 target datalayout = "e-m:w-i64:64-f80:128-n8:16:32:64-S128"
3 target triple = "x86_64-pc-windows-msvc"
4
5 declare void @might_crash(i8* %ehptr)
6 declare i32 @filt()
7 declare void @cleanup()
8 declare i32 @__C_specific_handler(...)
9 declare i32 @llvm.eh.typeid.for(i8*)
10
11 define void @resume_phi() {
12 entry:
13 invoke void @might_crash(i8* null)
14 to label %return unwind label %lpad1
15
16 lpad1:
17 %ehvals1 = landingpad { i8*, i32 } personality i32 (...)* @__C_specific_handler
18 catch i32 ()* @filt
19 %ehptr1 = extractvalue { i8*, i32 } %ehvals1, 0
20 %ehsel1 = extractvalue { i8*, i32 } %ehvals1, 1
21 %filt_sel = tail call i32 @llvm.eh.typeid.for(i8* bitcast (i32 ()* @filt to i8*))
22 %matches = icmp eq i32 %ehsel1, %filt_sel
23 br i1 %matches, label %__except, label %eh.resume
24
25 __except:
26 invoke void @might_crash(i8* %ehptr1)
27 to label %return unwind label %lpad2
28
29 lpad2:
30 %ehvals2 = landingpad { i8*, i32 } personality i32 (...)* @__C_specific_handler
31 cleanup
32 %ehptr2 = extractvalue { i8*, i32 } %ehvals2, 0
33 %ehsel2 = extractvalue { i8*, i32 } %ehvals2, 1
34 call void @cleanup()
35 br label %eh.resume
36
37 return:
38 ret void
39
40 eh.resume:
41 %ehptr.phi = phi i8* [ %ehptr1, %lpad1 ], [ %ehptr2, %lpad2 ]
42 %ehsel.phi = phi i32 [ %ehsel1, %lpad1 ], [ %ehsel2, %lpad2 ]
43 %ehval.phi1 = insertvalue { i8*, i32 } undef, i8* %ehptr.phi, 0
44 %ehval.phi2 = insertvalue { i8*, i32 } %ehval.phi1, i32 %ehsel.phi, 1
45 resume { i8*, i32 } %ehval.phi2
46 }
47
48 ; CHECK-LABEL: define void @resume_phi()
49 ; CHECK: invoke void @might_crash(i8* null)
50 ; CHECK: landingpad { i8*, i32 }
51 ; CHECK-NEXT: catch i32 ()* @filt
52 ; CHECK-NEXT: call i8* (...) @llvm.eh.actions(
53 ; CHECK-SAME: i32 1, i8* bitcast (i32 ()* @filt to i8*), i32 -1, i8* blockaddress(@resume_phi, %__except))
54 ; CHECK-NEXT: indirectbr {{.*}} [label %__except]
55 ;
56 ; CHECK: __except:
57 ; FIXME: This should not be undef, it should be the new landingpad value, which
58 ; should ultimately lower down to eax.
59 ; CHECK: invoke void @might_crash(i8* undef)
60 ; CHECK: landingpad { i8*, i32 }
61 ; CHECK-NEXT: cleanup
62 ; CHECK-NEXT: call i8* (...) @llvm.eh.actions(i32 0, void (i8*, i8*)* @resume_phi.cleanup)
63 ; CHECK-NEXT: indirectbr {{.*}} []
64
65 ; CHECK-LABEL: define internal void @resume_phi.cleanup(i8*, i8*)
66 ; CHECK: call void @cleanup()