<div dir="ltr">On further reflection, I think the nomenclature here is wrong. We need to try harder to disambiguate two concepts of SEH: the __try / __except constructs, and the Windows unwind and exception info format on x64, arm, and probably ppc. In LLVM MC, we currently use the terminology WinCFI and WinEH to refer to essentially the stuff in .pdata and .xdata respectively.<div><br></div><div>-fseh-exceptions and LangOpts.SEHExceptions are poorly named because the reader might assume that they enable an implementation of __try / __except, which is incorrect. Can you help me come up with a less confusing name? My strawmen are:</div><div>-fpdata-exceptions / PDataExceptions</div><div>-fxdata-exceptions / XDataExceptions</div><div>-fwin-eh-exceptions / WinEHExceptions</div><div>-fwin-cfi-exceptions / WinCFIExceptions<br></div><div><br></div><div>These names are meant to stand as alternative to -fsjlj-exceptions and dwarf cfi, the default.</div><div><br></div><div>Alternatively, is this option even useful? Would you be OK with completely removing this option in favor of only supporting .pdata exceptions and sjlj exceptions on mingw64 x64? I noticed that the mingwbuilds installer doesn't even present dwarf exceptions as an option anymore (did it ever?).</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Sep 15, 2014 at 11:36 AM, Yaron Keren <span dir="ltr"><<a href="mailto:yaron.keren@gmail.com" target="_blank">yaron.keren@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="rtl"><div dir="ltr">Great! thanks to everyone.</div></div><div class="HOEnZb"><div class="h5"><div class="gmail_extra"><br><div class="gmail_quote"><div dir="ltr">2014-09-15 20:19 GMT+03:00 Reid Kleckner <span dir="ltr"><<a href="mailto:reid@kleckner.net" target="_blank">reid@kleckner.net</a>></span>:</div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Author: rnk<br>
Date: Mon Sep 15 12:19:16 2014<br>
New Revision: 217790<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=217790&view=rev" target="_blank">http://llvm.org/viewvc/llvm-project?rev=217790&view=rev</a><br>
Log:<br>
Add -fseh-exceptions for MinGW-w64<br>
<br>
This adds a flag called -fseh-exceptions that uses the native Windows<br>
.pdata and .xdata unwind mechanism to throw exceptions. The other EH<br>
possibilities are DWARF and SJLJ exceptions.<br>
<br>
Patch by Martell Malone!<br>
<br>
Reviewed By: asl, rnk<br>
<br>
Differential Revision: <a href="http://reviews.llvm.org/D3419" target="_blank">http://reviews.llvm.org/D3419</a><br>
<br>
Added:<br>
cfe/trunk/test/CodeGenCXX/mingw-w64-seh-exceptions.cpp<br>
Modified:<br>
cfe/trunk/include/clang/Basic/LangOptions.def<br>
cfe/trunk/include/clang/Driver/CC1Options.td<br>
cfe/trunk/include/clang/Driver/ToolChain.h<br>
cfe/trunk/lib/CodeGen/CGException.cpp<br>
cfe/trunk/lib/Driver/Tools.cpp<br>
cfe/trunk/lib/Frontend/CompilerInvocation.cpp<br>
cfe/trunk/lib/Frontend/InitPreprocessor.cpp<br>
<br>
Modified: cfe/trunk/include/clang/Basic/LangOptions.def<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/LangOptions.def?rev=217790&r1=217789&r2=217790&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/LangOptions.def?rev=217790&r1=217789&r2=217790&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/include/clang/Basic/LangOptions.def (original)<br>
+++ cfe/trunk/include/clang/Basic/LangOptions.def Mon Sep 15 12:19:16 2014<br>
@@ -82,6 +82,7 @@ LANGOPT(Exceptions , 1, 0, "excep<br>
LANGOPT(ObjCExceptions , 1, 0, "Objective-C exceptions")<br>
LANGOPT(CXXExceptions , 1, 0, "C++ exceptions")<br>
LANGOPT(SjLjExceptions , 1, 0, "setjmp-longjump exception handling")<br>
+LANGOPT(SEHExceptions , 1, 0, "SEH exception handling")<br>
LANGOPT(TraditionalCPP , 1, 0, "traditional CPP emulation")<br>
LANGOPT(RTTI , 1, 1, "run-time type information")<br>
LANGOPT(RTTIData , 1, 1, "emit run-time type information data")<br>
<br>
Modified: cfe/trunk/include/clang/Driver/CC1Options.td<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/CC1Options.td?rev=217790&r1=217789&r2=217790&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/CC1Options.td?rev=217790&r1=217789&r2=217790&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/include/clang/Driver/CC1Options.td (original)<br>
+++ cfe/trunk/include/clang/Driver/CC1Options.td Mon Sep 15 12:19:16 2014<br>
@@ -435,6 +435,8 @@ def fblocks_runtime_optional : Flag<["-"<br>
HelpText<"Weakly link in the blocks runtime">;<br>
def fsjlj_exceptions : Flag<["-"], "fsjlj-exceptions">,<br>
HelpText<"Use SjLj style exceptions">;<br>
+def fseh_exceptions : Flag<["-"], "fseh-exceptions">,<br>
+ HelpText<"Use SEH style exceptions">;<br>
def split_dwarf_file : Separate<["-"], "split-dwarf-file">,<br>
HelpText<"File name to use for split dwarf debug info output">;<br>
def fno_wchar : Flag<["-"], "fno-wchar">,<br>
<br>
Modified: cfe/trunk/include/clang/Driver/ToolChain.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/ToolChain.h?rev=217790&r1=217789&r2=217790&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/ToolChain.h?rev=217790&r1=217789&r2=217790&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/include/clang/Driver/ToolChain.h (original)<br>
+++ cfe/trunk/include/clang/Driver/ToolChain.h Mon Sep 15 12:19:16 2014<br>
@@ -248,6 +248,9 @@ public:<br>
/// UseSjLjExceptions - Does this tool chain use SjLj exceptions.<br>
virtual bool UseSjLjExceptions() const { return false; }<br>
<br>
+ /// UseSEHExceptions - Does this tool chain use SEH exceptions.<br>
+ virtual bool UseSEHExceptions() const { return false; }<br>
+<br>
/// ComputeLLVMTriple - Return the LLVM target triple to use, after taking<br>
/// command line arguments into account.<br>
virtual std::string<br>
<br>
Modified: cfe/trunk/lib/CodeGen/CGException.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGException.cpp?rev=217790&r1=217789&r2=217790&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGException.cpp?rev=217790&r1=217789&r2=217790&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/lib/CodeGen/CGException.cpp (original)<br>
+++ cfe/trunk/lib/CodeGen/CGException.cpp Mon Sep 15 12:19:16 2014<br>
@@ -137,12 +137,14 @@ namespace {<br>
static const EHPersonality &get(const LangOptions &Lang);<br>
static const EHPersonality GNU_C;<br>
static const EHPersonality GNU_C_SJLJ;<br>
+ static const EHPersonality GNU_C_SEH;<br>
static const EHPersonality GNU_ObjC;<br>
static const EHPersonality GNUstep_ObjC;<br>
static const EHPersonality GNU_ObjCXX;<br>
static const EHPersonality NeXT_ObjC;<br>
static const EHPersonality GNU_CPlusPlus;<br>
static const EHPersonality GNU_CPlusPlus_SJLJ;<br>
+ static const EHPersonality GNU_CPlusPlus_SEH;<br>
};<br>
}<br>
<br>
@@ -150,12 +152,16 @@ const EHPersonality EHPersonality::GNU_C<br>
const EHPersonality<br>
EHPersonality::GNU_C_SJLJ = { "__gcc_personality_sj0", nullptr };<br>
const EHPersonality<br>
+EHPersonality::GNU_C_SEH = { "__gcc_personality_seh0", nullptr };<br>
+const EHPersonality<br>
EHPersonality::NeXT_ObjC = { "__objc_personality_v0", nullptr };<br>
const EHPersonality<br>
EHPersonality::GNU_CPlusPlus = { "__gxx_personality_v0", nullptr };<br>
const EHPersonality<br>
EHPersonality::GNU_CPlusPlus_SJLJ = { "__gxx_personality_sj0", nullptr };<br>
const EHPersonality<br>
+EHPersonality::GNU_CPlusPlus_SEH = { "__gxx_personality_seh0", nullptr };<br>
+const EHPersonality<br>
EHPersonality::GNU_ObjC = {"__gnu_objc_personality_v0", "objc_exception_throw"};<br>
const EHPersonality<br>
EHPersonality::GNU_ObjCXX = { "__gnustep_objcxx_personality_v0", nullptr };<br>
@@ -165,6 +171,8 @@ EHPersonality::GNUstep_ObjC = { "__gnust<br>
static const EHPersonality &getCPersonality(const LangOptions &L) {<br>
if (L.SjLjExceptions)<br>
return EHPersonality::GNU_C_SJLJ;<br>
+ if (L.SEHExceptions)<br>
+ return EHPersonality::GNU_C_SEH;<br>
return EHPersonality::GNU_C;<br>
}<br>
<br>
@@ -189,6 +197,8 @@ static const EHPersonality &getObjCPerso<br>
static const EHPersonality &getCXXPersonality(const LangOptions &L) {<br>
if (L.SjLjExceptions)<br>
return EHPersonality::GNU_CPlusPlus_SJLJ;<br>
+ else if (L.SEHExceptions)<br>
+ return EHPersonality::GNU_CPlusPlus_SEH;<br>
else<br>
return EHPersonality::GNU_CPlusPlus;<br>
}<br>
<br>
Modified: cfe/trunk/lib/Driver/Tools.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/Tools.cpp?rev=217790&r1=217789&r2=217790&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/Tools.cpp?rev=217790&r1=217789&r2=217790&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/lib/Driver/Tools.cpp (original)<br>
+++ cfe/trunk/lib/Driver/Tools.cpp Mon Sep 15 12:19:16 2014<br>
@@ -4112,6 +4112,8 @@ void Clang::ConstructJob(Compilation &C,<br>
<br>
if (getToolChain().UseSjLjExceptions())<br>
CmdArgs.push_back("-fsjlj-exceptions");<br>
+ else if (getToolChain().UseSEHExceptions())<br>
+ CmdArgs.push_back("-fseh-exceptions");<br>
<br>
// C++ "sane" operator new.<br>
if (!Args.hasFlag(options::OPT_fassume_sane_operator_new,<br>
<br>
Modified: cfe/trunk/lib/Frontend/CompilerInvocation.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/CompilerInvocation.cpp?rev=217790&r1=217789&r2=217790&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/CompilerInvocation.cpp?rev=217790&r1=217789&r2=217790&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/lib/Frontend/CompilerInvocation.cpp (original)<br>
+++ cfe/trunk/lib/Frontend/CompilerInvocation.cpp Mon Sep 15 12:19:16 2014<br>
@@ -1431,6 +1431,7 @@ static void ParseLangArgs(LangOptions &O<br>
Opts.ObjCExceptions = Args.hasArg(OPT_fobjc_exceptions);<br>
Opts.CXXExceptions = Args.hasArg(OPT_fcxx_exceptions);<br>
Opts.SjLjExceptions = Args.hasArg(OPT_fsjlj_exceptions);<br>
+ Opts.SEHExceptions = Args.hasArg(OPT_fseh_exceptions);<br>
Opts.TraditionalCPP = Args.hasArg(OPT_traditional_cpp);<br>
<br>
Opts.RTTI = !Args.hasArg(OPT_fno_rtti);<br>
<br>
Modified: cfe/trunk/lib/Frontend/InitPreprocessor.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/InitPreprocessor.cpp?rev=217790&r1=217789&r2=217790&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/InitPreprocessor.cpp?rev=217790&r1=217789&r2=217790&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/lib/Frontend/InitPreprocessor.cpp (original)<br>
+++ cfe/trunk/lib/Frontend/InitPreprocessor.cpp Mon Sep 15 12:19:16 2014<br>
@@ -556,6 +556,8 @@ static void InitializePredefinedMacros(c<br>
Builder.defineMacro("__GXX_RTTI");<br>
if (LangOpts.SjLjExceptions)<br>
Builder.defineMacro("__USING_SJLJ_EXCEPTIONS__");<br>
+ if (LangOpts.SEHExceptions)<br>
+ Builder.defineMacro("__SEH__");<br>
<br>
if (LangOpts.Deprecated)<br>
Builder.defineMacro("__DEPRECATED");<br>
<br>
Added: cfe/trunk/test/CodeGenCXX/mingw-w64-seh-exceptions.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/mingw-w64-seh-exceptions.cpp?rev=217790&view=auto" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/mingw-w64-seh-exceptions.cpp?rev=217790&view=auto</a><br>
==============================================================================<br>
--- cfe/trunk/test/CodeGenCXX/mingw-w64-seh-exceptions.cpp (added)<br>
+++ cfe/trunk/test/CodeGenCXX/mingw-w64-seh-exceptions.cpp Mon Sep 15 12:19:16 2014<br>
@@ -0,0 +1,19 @@<br>
+// RUN: %clang_cc1 %s -fexceptions -fseh-exceptions -emit-llvm -triple x86_64-w64-windows-gnu -o - | FileCheck %s<br>
+<br>
+extern "C" void foo();<br>
+extern "C" void bar();<br>
+<br>
+struct Cleanup {<br>
+ ~Cleanup() {<br>
+ bar();<br>
+ }<br>
+};<br>
+<br>
+extern "C" void test() {<br>
+ Cleanup x;<br>
+ foo();<br>
+}<br>
+<br>
+// CHECK: define void @test()<br>
+// CHECK: invoke void @foo()<br>
+// CHECK: landingpad { i8*, i32 } personality i8* bitcast (i32 (...)* @__gxx_personality_seh0 to i8*)<br>
<br>
<br>
_______________________________________________<br>
cfe-commits mailing list<br>
<a href="mailto:cfe-commits@cs.uiuc.edu" target="_blank">cfe-commits@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits</a><br>
</blockquote></div><br></div>
</div></div><br>_______________________________________________<br>
cfe-commits mailing list<br>
<a href="mailto:cfe-commits@cs.uiuc.edu">cfe-commits@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits</a><br>
<br></blockquote></div><br></div>