mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-07-22 23:24:59 +00:00
[WinEH] Put finally pointers in the handler scope table field
We were putting them in the filter field, which is correct for 64-bit but wrong for 32-bit. Also switch the order of scope table entry emission so outermost entries are emitted first, and fix an obvious state assignment bug. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@239574 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -613,8 +613,8 @@ void WinException::emitExceptHandlerTable(const MachineFunction *MF) {
|
|||||||
// For each action in each lpad, emit one of these:
|
// For each action in each lpad, emit one of these:
|
||||||
// struct ScopeTableEntry {
|
// struct ScopeTableEntry {
|
||||||
// int32_t EnclosingLevel;
|
// int32_t EnclosingLevel;
|
||||||
// int32_t (__cdecl *FilterOrFinally)();
|
// int32_t (__cdecl *Filter)();
|
||||||
// void *HandlerLabel;
|
// void *HandlerOrFinally;
|
||||||
// };
|
// };
|
||||||
//
|
//
|
||||||
// The "outermost" action will use BaseState as its enclosing level. Each
|
// The "outermost" action will use BaseState as its enclosing level. Each
|
||||||
@@ -625,21 +625,20 @@ void WinException::emitExceptHandlerTable(const MachineFunction *MF) {
|
|||||||
assert(CurState + int(LPInfo->SEHHandlers.size()) - 1 ==
|
assert(CurState + int(LPInfo->SEHHandlers.size()) - 1 ==
|
||||||
LPInfo->WinEHState &&
|
LPInfo->WinEHState &&
|
||||||
"gaps in the SEH scope table");
|
"gaps in the SEH scope table");
|
||||||
for (const SEHHandler &Handler : LPInfo->SEHHandlers) {
|
for (auto I = LPInfo->SEHHandlers.rbegin(), E = LPInfo->SEHHandlers.rend();
|
||||||
// Emit the filter or finally function pointer, if present. Otherwise,
|
I != E; ++I) {
|
||||||
// emit '0' to indicate a catch-all.
|
const SEHHandler &Handler = *I;
|
||||||
const Function *F = Handler.FilterOrFinally;
|
|
||||||
const MCExpr *FilterOrFinally =
|
|
||||||
create32bitRef(F ? Asm->getSymbol(F) : nullptr);
|
|
||||||
|
|
||||||
// Compute the recovery address, which is a block address or null.
|
|
||||||
const BlockAddress *BA = Handler.RecoverBA;
|
const BlockAddress *BA = Handler.RecoverBA;
|
||||||
const MCExpr *RecoverBBOrNull =
|
const Function *F = Handler.FilterOrFinally;
|
||||||
create32bitRef(BA ? Asm->GetBlockAddressSymbol(BA) : nullptr);
|
assert(F && "cannot catch all in 32-bit SEH without filter function");
|
||||||
|
const MCExpr *FilterOrNull =
|
||||||
|
create32bitRef(BA ? Asm->getSymbol(F) : nullptr);
|
||||||
|
const MCExpr *ExceptOrFinally = create32bitRef(
|
||||||
|
BA ? Asm->GetBlockAddressSymbol(BA) : Asm->getSymbol(F));
|
||||||
|
|
||||||
OS.EmitIntValue(EnclosingLevel, 4);
|
OS.EmitIntValue(EnclosingLevel, 4);
|
||||||
OS.EmitValue(FilterOrFinally, 4);
|
OS.EmitValue(FilterOrNull, 4);
|
||||||
OS.EmitValue(RecoverBBOrNull, 4);
|
OS.EmitValue(ExceptOrFinally, 4);
|
||||||
|
|
||||||
// The next state unwinds to this state.
|
// The next state unwinds to this state.
|
||||||
EnclosingLevel = CurState;
|
EnclosingLevel = CurState;
|
||||||
|
@@ -508,7 +508,7 @@ void WinEHStatePass::addSEHStateStores(Function &F, MachineModuleInfo &MMI) {
|
|||||||
// Look up the state number of the landingpad this unwinds to.
|
// Look up the state number of the landingpad this unwinds to.
|
||||||
LandingPadInst *LPI = II->getUnwindDest()->getLandingPadInst();
|
LandingPadInst *LPI = II->getUnwindDest()->getLandingPadInst();
|
||||||
auto InsertionPair =
|
auto InsertionPair =
|
||||||
FuncInfo.LandingPadStateMap.insert(std::make_pair(LPI, 0));
|
FuncInfo.LandingPadStateMap.insert(std::make_pair(LPI, CurState));
|
||||||
auto Iter = InsertionPair.first;
|
auto Iter = InsertionPair.first;
|
||||||
int &State = Iter->second;
|
int &State = Iter->second;
|
||||||
bool Inserted = InsertionPair.second;
|
bool Inserted = InsertionPair.second;
|
||||||
|
@@ -1,4 +1,6 @@
|
|||||||
; RUN: llc -mtriple=x86_64-windows-msvc < %s | FileCheck %s
|
; RUN: llc -mtriple=x86_64-windows-msvc < %s | FileCheck %s --check-prefix=X64
|
||||||
|
; RUN: sed -e 's/__C_specific_handler/_except_handler3/' %s | \
|
||||||
|
; RUN: llc -mtriple=i686-windows-msvc | FileCheck %s --check-prefix=X86
|
||||||
|
|
||||||
@str_recovered = internal unnamed_addr constant [10 x i8] c"recovered\00", align 1
|
@str_recovered = internal unnamed_addr constant [10 x i8] c"recovered\00", align 1
|
||||||
|
|
||||||
@@ -32,17 +34,32 @@ terminate.lpad: ; preds = %lpad
|
|||||||
unreachable
|
unreachable
|
||||||
}
|
}
|
||||||
|
|
||||||
; CHECK-LABEL: main:
|
; X64-LABEL: main:
|
||||||
; CHECK: .seh_handlerdata
|
; X64: retq
|
||||||
; CHECK-NEXT: .long 1
|
|
||||||
; CHECK-NEXT: .long .Ltmp0@IMGREL
|
|
||||||
; CHECK-NEXT: .long .Ltmp1@IMGREL
|
|
||||||
; CHECK-NEXT: .long main.cleanup@IMGREL
|
|
||||||
; CHECK-NEXT: .long 0
|
|
||||||
|
|
||||||
; CHECK-LABEL: main.cleanup:
|
; X64: .seh_handlerdata
|
||||||
; CHECK: callq puts
|
; X64-NEXT: .long 1
|
||||||
; CHECK: retq
|
; X64-NEXT: .long .Ltmp0@IMGREL
|
||||||
|
; X64-NEXT: .long .Ltmp1@IMGREL
|
||||||
|
; X64-NEXT: .long main.cleanup@IMGREL
|
||||||
|
; X64-NEXT: .long 0
|
||||||
|
|
||||||
|
; X64-LABEL: main.cleanup:
|
||||||
|
; X64: callq puts
|
||||||
|
; X64: retq
|
||||||
|
|
||||||
|
; X86-LABEL: _main:
|
||||||
|
; X86: retl
|
||||||
|
|
||||||
|
; X86: .section .xdata,"dr"
|
||||||
|
; X86: L__ehtable$main:
|
||||||
|
; X86-NEXT: .long -1
|
||||||
|
; X86-NEXT: .long 0
|
||||||
|
; X86-NEXT: .long _main.cleanup
|
||||||
|
|
||||||
|
; X86-LABEL: _main.cleanup:
|
||||||
|
; X86: calll _puts
|
||||||
|
; X86: retl
|
||||||
|
|
||||||
declare i32 @__C_specific_handler(...)
|
declare i32 @__C_specific_handler(...)
|
||||||
|
|
||||||
|
@@ -92,11 +92,11 @@ __try.cont:
|
|||||||
; CHECK: .section .xdata,"dr"
|
; CHECK: .section .xdata,"dr"
|
||||||
; CHECK: L__ehtable$safe_div:
|
; CHECK: L__ehtable$safe_div:
|
||||||
; CHECK-NEXT: .long -1
|
; 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 _safe_div_filt1
|
||||||
; CHECK-NEXT: .long [[handler1]]
|
; CHECK-NEXT: .long [[handler1]]
|
||||||
|
; CHECK-NEXT: .long 0
|
||||||
|
; CHECK-NEXT: .long _safe_div_filt0
|
||||||
|
; CHECK-NEXT: .long [[handler0]]
|
||||||
|
|
||||||
define void @try_body(i32* %r, i32* %n, i32* %d) {
|
define void @try_body(i32* %r, i32* %n, i32* %d) {
|
||||||
entry:
|
entry:
|
||||||
|
@@ -6,16 +6,27 @@ declare i32 @_except_handler4(...)
|
|||||||
declare i32 @__CxxFrameHandler3(...)
|
declare i32 @__CxxFrameHandler3(...)
|
||||||
declare void @llvm.eh.begincatch(i8*, i8*)
|
declare void @llvm.eh.begincatch(i8*, i8*)
|
||||||
declare void @llvm.eh.endcatch()
|
declare void @llvm.eh.endcatch()
|
||||||
|
declare i32 @llvm.eh.typeid.for(i8*)
|
||||||
|
|
||||||
|
define internal i32 @catchall_filt() {
|
||||||
|
ret i32 1
|
||||||
|
}
|
||||||
|
|
||||||
define void @use_except_handler3() {
|
define void @use_except_handler3() {
|
||||||
|
entry:
|
||||||
invoke void @may_throw_or_crash()
|
invoke void @may_throw_or_crash()
|
||||||
to label %cont unwind label %catchall
|
to label %cont unwind label %catchall
|
||||||
cont:
|
cont:
|
||||||
ret void
|
ret void
|
||||||
catchall:
|
catchall:
|
||||||
landingpad { i8*, i32 } personality i32 (...)* @_except_handler3
|
%0 = landingpad { i8*, i32 } personality i32 (...)* @_except_handler3
|
||||||
catch i8* null
|
catch i8* bitcast (i32 ()* @catchall_filt to i8*)
|
||||||
br label %cont
|
%1 = extractvalue { i8*, i32 } %0, 1
|
||||||
|
%2 = call i32 @llvm.eh.typeid.for(i8* bitcast (i32 ()* @catchall_filt to i8*)) #4
|
||||||
|
%matches = icmp eq i32 %1, %2
|
||||||
|
br i1 %matches, label %cont, label %eh.resume
|
||||||
|
eh.resume:
|
||||||
|
resume { i8*, i32 } %0
|
||||||
}
|
}
|
||||||
|
|
||||||
; CHECK-LABEL: _use_except_handler3:
|
; CHECK-LABEL: _use_except_handler3:
|
||||||
@@ -37,18 +48,24 @@ catchall:
|
|||||||
; CHECK: .section .xdata,"dr"
|
; CHECK: .section .xdata,"dr"
|
||||||
; CHECK-LABEL: L__ehtable$use_except_handler3:
|
; CHECK-LABEL: L__ehtable$use_except_handler3:
|
||||||
; CHECK-NEXT: .long -1
|
; CHECK-NEXT: .long -1
|
||||||
; CHECK-NEXT: .long 0
|
; CHECK-NEXT: .long _catchall_filt
|
||||||
; CHECK-NEXT: .long Ltmp{{[0-9]+}}
|
; CHECK-NEXT: .long Ltmp{{[0-9]+}}
|
||||||
|
|
||||||
define void @use_except_handler4() {
|
define void @use_except_handler4() {
|
||||||
|
entry:
|
||||||
invoke void @may_throw_or_crash()
|
invoke void @may_throw_or_crash()
|
||||||
to label %cont unwind label %catchall
|
to label %cont unwind label %catchall
|
||||||
cont:
|
cont:
|
||||||
ret void
|
ret void
|
||||||
catchall:
|
catchall:
|
||||||
landingpad { i8*, i32 } personality i32 (...)* @_except_handler4
|
%0 = landingpad { i8*, i32 } personality i32 (...)* @_except_handler4
|
||||||
catch i8* null
|
catch i8* bitcast (i32 ()* @catchall_filt to i8*)
|
||||||
br label %cont
|
%1 = extractvalue { i8*, i32 } %0, 1
|
||||||
|
%2 = call i32 @llvm.eh.typeid.for(i8* bitcast (i32 ()* @catchall_filt to i8*)) #4
|
||||||
|
%matches = icmp eq i32 %1, %2
|
||||||
|
br i1 %matches, label %cont, label %eh.resume
|
||||||
|
eh.resume:
|
||||||
|
resume { i8*, i32 } %0
|
||||||
}
|
}
|
||||||
|
|
||||||
; CHECK-LABEL: _use_except_handler4:
|
; CHECK-LABEL: _use_except_handler4:
|
||||||
@@ -77,7 +94,7 @@ catchall:
|
|||||||
; CHECK-NEXT: .long 9999
|
; CHECK-NEXT: .long 9999
|
||||||
; CHECK-NEXT: .long 0
|
; CHECK-NEXT: .long 0
|
||||||
; CHECK-NEXT: .long -2
|
; CHECK-NEXT: .long -2
|
||||||
; CHECK-NEXT: .long 0
|
; CHECK-NEXT: .long _catchall_filt
|
||||||
; CHECK-NEXT: .long Ltmp{{[0-9]+}}
|
; CHECK-NEXT: .long Ltmp{{[0-9]+}}
|
||||||
|
|
||||||
define void @use_CxxFrameHandler3() {
|
define void @use_CxxFrameHandler3() {
|
||||||
|
Reference in New Issue
Block a user