diff --git a/lib/CodeGen/AsmPrinter/AsmPrinter.cpp b/lib/CodeGen/AsmPrinter/AsmPrinter.cpp index f079a8c332c..621ee53c97a 100644 --- a/lib/CodeGen/AsmPrinter/AsmPrinter.cpp +++ b/lib/CodeGen/AsmPrinter/AsmPrinter.cpp @@ -256,7 +256,10 @@ bool AsmPrinter::doInitialization(Module &M) { switch (MAI->getWinEHEncodingType()) { default: llvm_unreachable("unsupported unwinding information encoding"); case WinEH::EncodingType::Itanium: - ES = new Win64Exception(this); + if (!EnableMonoEH) + ES = new Win64Exception(this); + else + ES = new Win64Exception(this, true); break; } break; diff --git a/lib/CodeGen/AsmPrinter/DwarfMonoException.cpp b/lib/CodeGen/AsmPrinter/DwarfMonoException.cpp index b2a4a415857..a7dfe018b1c 100644 --- a/lib/CodeGen/AsmPrinter/DwarfMonoException.cpp +++ b/lib/CodeGen/AsmPrinter/DwarfMonoException.cpp @@ -396,7 +396,6 @@ void DwarfMonoException::EmitMonoLSDA(const FunctionEHFrameInfo *EFI) { [](const LandingPadInfo *L, const LandingPadInfo *R) { return L->TypeIds < R->TypeIds; }); - assert(Asm->MAI->getExceptionHandlingType() == ExceptionHandling::DwarfCFI); // The type_info itself is emitted int TTypeEncoding = dwarf::DW_EH_PE_udata4; diff --git a/lib/CodeGen/AsmPrinter/Win64Exception.cpp b/lib/CodeGen/AsmPrinter/Win64Exception.cpp index 0f0ad755835..107b2cd831b 100644 --- a/lib/CodeGen/AsmPrinter/Win64Exception.cpp +++ b/lib/CodeGen/AsmPrinter/Win64Exception.cpp @@ -39,7 +39,11 @@ using namespace llvm; Win64Exception::Win64Exception(AsmPrinter *A) : EHStreamer(A), shouldEmitPersonality(false), shouldEmitLSDA(false), - shouldEmitMoves(false) {} + shouldEmitMoves(false), disableEmitPersonality(false) {} + +Win64Exception::Win64Exception (AsmPrinter *A, bool disableEmitPersonality) + : EHStreamer(A), shouldEmitPersonality(false), shouldEmitLSDA(false), + shouldEmitMoves(false), disableEmitPersonality(disableEmitPersonality) {} Win64Exception::~Win64Exception() {} @@ -62,8 +66,9 @@ void Win64Exception::beginFunction(const MachineFunction *MF) { unsigned PerEncoding = TLOF.getPersonalityEncoding(); const Function *Per = MMI->getPersonalities()[MMI->getPersonalityIndex()]; - shouldEmitPersonality = hasLandingPads && - PerEncoding != dwarf::DW_EH_PE_omit && Per; + if (!disableEmitPersonality) + shouldEmitPersonality = hasLandingPads && + PerEncoding != dwarf::DW_EH_PE_omit && Per; unsigned LSDAEncoding = TLOF.getLSDAEncoding(); shouldEmitLSDA = shouldEmitPersonality && diff --git a/lib/CodeGen/AsmPrinter/Win64Exception.h b/lib/CodeGen/AsmPrinter/Win64Exception.h index 538e1328157..f43877fbb64 100644 --- a/lib/CodeGen/AsmPrinter/Win64Exception.h +++ b/lib/CodeGen/AsmPrinter/Win64Exception.h @@ -29,11 +29,15 @@ class Win64Exception : public EHStreamer { /// Per-function flag to indicate if frame moves info should be emitted. bool shouldEmitMoves; + /// Per-function flag to indicate if personality info should be disabled. + bool disableEmitPersonality; + public: //===--------------------------------------------------------------------===// // Main entry points. // Win64Exception(AsmPrinter *A); + Win64Exception(AsmPrinter *A, bool disableEmitPersonality); virtual ~Win64Exception(); /// Emit all exception information that should come after the content. diff --git a/lib/Target/X86/X86CallingConv.td b/lib/Target/X86/X86CallingConv.td index 3ef8383bfe5..e7c04b73e2f 100644 --- a/lib/Target/X86/X86CallingConv.td +++ b/lib/Target/X86/X86CallingConv.td @@ -383,7 +383,9 @@ def CC_X86_64_AnyReg : CallingConv<[ def CC_X86_64_Mono : CallingConv<[ CCIfInReg>, - + // Mingw64 and native Win64 use Win64 CC + CCIfSubtarget<"isTargetWin64()", CCDelegateTo>, + // Otherwise, drop to normal X86-64 CC CCDelegateTo ]>; diff --git a/lib/Target/X86/X86FrameLowering.cpp b/lib/Target/X86/X86FrameLowering.cpp index 2dbd407388c..dcee32215a2 100644 --- a/lib/Target/X86/X86FrameLowering.cpp +++ b/lib/Target/X86/X86FrameLowering.cpp @@ -473,8 +473,9 @@ void X86FrameLowering::emitPrologue(MachineFunction &MF) const { MF.getTarget().getMCAsmInfo()->getExceptionHandlingType() == ExceptionHandling::WinEH; // Not necessarily synonymous with IsWin64. bool NeedsWinEH = IsWinEH && Fn->needsUnwindTableEntry(); - bool NeedsDwarfCFI = - !IsWinEH && (MMI.hasDebugInfo() || Fn->needsUnwindTableEntry()); + bool NeedsDwarfCFI = Fn->getCallingConv() == CallingConv::Mono ? + (MMI.hasDebugInfo() || Fn->needsUnwindTableEntry()) : + !IsWinEH && (MMI.hasDebugInfo () || Fn->needsUnwindTableEntry ()); bool UseLEA = STI.useLeaForSP(); unsigned StackAlign = getStackAlignment(); unsigned SlotSize = RegInfo->getSlotSize();