[llvm] r235649 - [WinEH] Replace more lpad value uses with undef
Reid Kleckner
reid at kleckner.net
Thu Apr 23 14:22:30 PDT 2015
Author: rnk
Date: Thu Apr 23 16:22:30 2015
New Revision: 235649
URL: http://llvm.org/viewvc/llvm-project?rev=235649&view=rev
Log:
[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.
Added:
llvm/trunk/test/CodeGen/WinEH/seh-resume-phi.ll
Modified:
llvm/trunk/lib/CodeGen/WinEHPrepare.cpp
Modified: llvm/trunk/lib/CodeGen/WinEHPrepare.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/WinEHPrepare.cpp?rev=235649&r1=235648&r2=235649&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/WinEHPrepare.cpp (original)
+++ llvm/trunk/lib/CodeGen/WinEHPrepare.cpp Thu Apr 23 16:22:30 2015
@@ -696,10 +696,6 @@ bool WinEHPrepare::prepareExceptionHandl
Invoke->setUnwindDest(NewLPadBB);
}
- // If anyone is still using the old landingpad value, just give them undef
- // instead. The eh pointer and selector values are not real.
- LPad->replaceAllUsesWith(UndefValue::get(LPad->getType()));
-
// Replace the mapping of any nested landing pad that previously mapped
// to this landing pad with a referenced to the cloned version.
for (auto &LPadPair : NestedLPtoOriginalLP) {
@@ -709,11 +705,26 @@ bool WinEHPrepare::prepareExceptionHandl
}
}
- // Replace uses of the old lpad in phis with this block and delete the old
- // block.
- LPadBB->replaceSuccessorsPhiUsesWith(NewLPadBB);
- LPadBB->getTerminator()->eraseFromParent();
- new UnreachableInst(LPadBB->getContext(), LPadBB);
+ // Replace all extracted values with undef and ultimately replace the
+ // landingpad with undef.
+ // FIXME: This doesn't handle SEH GetExceptionCode(). For now, we just give
+ // out undef until we figure out the codegen support.
+ SmallVector<Instruction *, 4> Extracts;
+ for (User *U : LPad->users()) {
+ auto *E = dyn_cast<ExtractValueInst>(U);
+ if (!E)
+ continue;
+ assert(E->getNumIndices() == 1 &&
+ "Unexpected operation: extracting both landing pad values");
+ unsigned Idx = E->getIndices()[0];
+ assert(Idx == 0 || Idx == 1);
+ Extracts.push_back(E);
+ }
+ for (Instruction *E : Extracts) {
+ E->replaceAllUsesWith(UndefValue::get(E->getType()));
+ E->eraseFromParent();
+ }
+ LPad->replaceAllUsesWith(UndefValue::get(LPad->getType()));
// Add a call to describe the actions for this landing pad.
std::vector<Value *> ActionArgs;
Added: llvm/trunk/test/CodeGen/WinEH/seh-resume-phi.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/WinEH/seh-resume-phi.ll?rev=235649&view=auto
==============================================================================
--- llvm/trunk/test/CodeGen/WinEH/seh-resume-phi.ll (added)
+++ llvm/trunk/test/CodeGen/WinEH/seh-resume-phi.ll Thu Apr 23 16:22:30 2015
@@ -0,0 +1,67 @@
+; RUN: opt -S -winehprepare -sehprepare < %s | FileCheck %s
+
+target datalayout = "e-m:w-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-pc-windows-msvc"
+
+declare void @might_crash(i8* %ehptr)
+declare i32 @filt()
+declare void @cleanup()
+declare i32 @__C_specific_handler(...)
+declare i32 @llvm.eh.typeid.for(i8*)
+
+define void @resume_phi() {
+entry:
+ invoke void @might_crash(i8* null)
+ to label %return unwind label %lpad1
+
+lpad1:
+ %ehvals1 = landingpad { i8*, i32 } personality i32 (...)* @__C_specific_handler
+ catch i32 ()* @filt
+ %ehptr1 = extractvalue { i8*, i32 } %ehvals1, 0
+ %ehsel1 = extractvalue { i8*, i32 } %ehvals1, 1
+ %filt_sel = tail call i32 @llvm.eh.typeid.for(i8* bitcast (i32 ()* @filt to i8*))
+ %matches = icmp eq i32 %ehsel1, %filt_sel
+ br i1 %matches, label %__except, label %eh.resume
+
+__except:
+ invoke void @might_crash(i8* %ehptr1)
+ to label %return unwind label %lpad2
+
+lpad2:
+ %ehvals2 = landingpad { i8*, i32 } personality i32 (...)* @__C_specific_handler
+ cleanup
+ %ehptr2 = extractvalue { i8*, i32 } %ehvals2, 0
+ %ehsel2 = extractvalue { i8*, i32 } %ehvals2, 1
+ call void @cleanup()
+ br label %eh.resume
+
+return:
+ ret void
+
+eh.resume:
+ %ehptr.phi = phi i8* [ %ehptr1, %lpad1 ], [ %ehptr2, %lpad2 ]
+ %ehsel.phi = phi i32 [ %ehsel1, %lpad1 ], [ %ehsel2, %lpad2 ]
+ %ehval.phi1 = insertvalue { i8*, i32 } undef, i8* %ehptr.phi, 0
+ %ehval.phi2 = insertvalue { i8*, i32 } %ehval.phi1, i32 %ehsel.phi, 1
+ resume { i8*, i32 } %ehval.phi2
+}
+
+; CHECK-LABEL: define void @resume_phi()
+; CHECK: invoke void @might_crash(i8* null)
+; CHECK: landingpad { i8*, i32 }
+; CHECK-NEXT: catch i32 ()* @filt
+; CHECK-NEXT: call i8* (...) @llvm.eh.actions(
+; CHECK-SAME: i32 1, i8* bitcast (i32 ()* @filt to i8*), i32 -1, i8* blockaddress(@resume_phi, %__except))
+; CHECK-NEXT: indirectbr {{.*}} [label %__except]
+;
+; CHECK: __except:
+; FIXME: This should not be undef, it should be the new landingpad value, which
+; should ultimately lower down to eax.
+; CHECK: invoke void @might_crash(i8* undef)
+; CHECK: landingpad { i8*, i32 }
+; CHECK-NEXT: cleanup
+; CHECK-NEXT: call i8* (...) @llvm.eh.actions(i32 0, void (i8*, i8*)* @resume_phi.cleanup)
+; CHECK-NEXT: indirectbr {{.*}} []
+
+; CHECK-LABEL: define internal void @resume_phi.cleanup(i8*, i8*)
+; CHECK: call void @cleanup()
More information about the llvm-commits
mailing list