From: Reid Kleckner Date: Thu, 17 Sep 2015 17:04:13 +0000 (+0000) Subject: Use the MSVC SEH personalities on Mingw X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=5b33399542ab0a26751a6c3d077b2ad5a400f4b5;p=clang Use the MSVC SEH personalities on Mingw Mingw generally wraps an old copy of msvcrt.dll which has these personalities, so things should work out, or so I hear. I haven't tested it. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@247902 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/CodeGen/CGException.cpp b/lib/CodeGen/CGException.cpp index c5b1c102ee..85204f4c9a 100644 --- a/lib/CodeGen/CGException.cpp +++ b/lib/CodeGen/CGException.cpp @@ -189,14 +189,16 @@ const EHPersonality &EHPersonality::get(CodeGenModule &CGM, const llvm::Triple &T = CGM.getTarget().getTriple(); const LangOptions &L = CGM.getLangOpts(); + // Functions using SEH get an SEH personality. + if (FD && FD->usesSEHTry()) + return getSEHPersonalityMSVC(T); + // Try to pick a personality function that is compatible with MSVC if we're // not compiling Obj-C. Obj-C users better have an Obj-C runtime that supports // the GCC-style personality function. if (T.isWindowsMSVCEnvironment() && !L.ObjC1) { if (L.SjLjExceptions) return EHPersonality::GNU_CPlusPlus_SJLJ; - else if (FD && FD->usesSEHTry()) - return getSEHPersonalityMSVC(T); else return EHPersonality::MSVC_CxxFrameHandler3; } diff --git a/test/CodeGen/exceptions-seh-new.c b/test/CodeGen/exceptions-seh-new.c index 2fc4f1b88d..795277bd9b 100644 --- a/test/CodeGen/exceptions-seh-new.c +++ b/test/CodeGen/exceptions-seh-new.c @@ -2,6 +2,10 @@ // RUN: | FileCheck %s --check-prefix=CHECK --check-prefix=X64 // RUN: %clang_cc1 %s -triple i686-pc-win32 -fms-extensions -fnew-ms-eh -emit-llvm -o - \ // RUN: | FileCheck %s --check-prefix=CHECK --check-prefix=X86 +// RUN: %clang_cc1 %s -triple i686-pc-windows-gnu -fms-extensions -fnew-ms-eh -emit-llvm -o - \ +// RUN: | FileCheck %s --check-prefix=X86-GNU +// RUN: %clang_cc1 %s -triple x86_64-pc-windows-gnu -fms-extensions -fnew-ms-eh -emit-llvm -o - \ +// RUN: | FileCheck %s --check-prefix=X64-GNU void try_body(int numerator, int denominator, int *myres) { *myres = numerator / denominator; @@ -55,6 +59,12 @@ int safe_div(int numerator, int denominator, int *res) { // X86: store i32 %{{.*}}, i32* // X86: ret i32 1 +// Mingw uses msvcrt, so it can also use _except_handler3. +// X86-GNU-LABEL: define i32 @safe_div(i32 %numerator, i32 %denominator, i32* %res) +// X86-GNU-SAME: personality i8* bitcast (i32 (...)* @_except_handler3 to i8*) +// X64-GNU-LABEL: define i32 @safe_div(i32 %numerator, i32 %denominator, i32* %res) +// X64-GNU-SAME: personality i8* bitcast (i32 (...)* @__C_specific_handler to i8*) + void j(void); int filter_expr_capture(void) {