r217790 - Add -fseh-exceptions for MinGW-w64

Yaron Keren yaron.keren at gmail.com
Mon Sep 15 11:36:44 PDT 2014


Great! thanks to everyone.

2014-09-15 20:19 GMT+03:00 Reid Kleckner <reid at kleckner.net>:

> Author: rnk
> Date: Mon Sep 15 12:19:16 2014
> New Revision: 217790
>
> URL: http://llvm.org/viewvc/llvm-project?rev=217790&view=rev
> Log:
> Add -fseh-exceptions for MinGW-w64
>
> This adds a flag called -fseh-exceptions that uses the native Windows
> .pdata and .xdata unwind mechanism to throw exceptions. The other EH
> possibilities are DWARF and SJLJ exceptions.
>
> Patch by Martell Malone!
>
> Reviewed By: asl, rnk
>
> Differential Revision: http://reviews.llvm.org/D3419
>
> Added:
>     cfe/trunk/test/CodeGenCXX/mingw-w64-seh-exceptions.cpp
> Modified:
>     cfe/trunk/include/clang/Basic/LangOptions.def
>     cfe/trunk/include/clang/Driver/CC1Options.td
>     cfe/trunk/include/clang/Driver/ToolChain.h
>     cfe/trunk/lib/CodeGen/CGException.cpp
>     cfe/trunk/lib/Driver/Tools.cpp
>     cfe/trunk/lib/Frontend/CompilerInvocation.cpp
>     cfe/trunk/lib/Frontend/InitPreprocessor.cpp
>
> Modified: cfe/trunk/include/clang/Basic/LangOptions.def
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/LangOptions.def?rev=217790&r1=217789&r2=217790&view=diff
>
> ==============================================================================
> --- cfe/trunk/include/clang/Basic/LangOptions.def (original)
> +++ cfe/trunk/include/clang/Basic/LangOptions.def Mon Sep 15 12:19:16 2014
> @@ -82,6 +82,7 @@ LANGOPT(Exceptions        , 1, 0, "excep
>  LANGOPT(ObjCExceptions    , 1, 0, "Objective-C exceptions")
>  LANGOPT(CXXExceptions     , 1, 0, "C++ exceptions")
>  LANGOPT(SjLjExceptions    , 1, 0, "setjmp-longjump exception handling")
> +LANGOPT(SEHExceptions     , 1, 0, "SEH exception handling")
>  LANGOPT(TraditionalCPP    , 1, 0, "traditional CPP emulation")
>  LANGOPT(RTTI              , 1, 1, "run-time type information")
>  LANGOPT(RTTIData          , 1, 1, "emit run-time type information data")
>
> Modified: cfe/trunk/include/clang/Driver/CC1Options.td
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/CC1Options.td?rev=217790&r1=217789&r2=217790&view=diff
>
> ==============================================================================
> --- cfe/trunk/include/clang/Driver/CC1Options.td (original)
> +++ cfe/trunk/include/clang/Driver/CC1Options.td Mon Sep 15 12:19:16 2014
> @@ -435,6 +435,8 @@ def fblocks_runtime_optional : Flag<["-"
>    HelpText<"Weakly link in the blocks runtime">;
>  def fsjlj_exceptions : Flag<["-"], "fsjlj-exceptions">,
>    HelpText<"Use SjLj style exceptions">;
> +def fseh_exceptions : Flag<["-"], "fseh-exceptions">,
> +  HelpText<"Use SEH style exceptions">;
>  def split_dwarf_file : Separate<["-"], "split-dwarf-file">,
>    HelpText<"File name to use for split dwarf debug info output">;
>  def fno_wchar : Flag<["-"], "fno-wchar">,
>
> Modified: cfe/trunk/include/clang/Driver/ToolChain.h
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/ToolChain.h?rev=217790&r1=217789&r2=217790&view=diff
>
> ==============================================================================
> --- cfe/trunk/include/clang/Driver/ToolChain.h (original)
> +++ cfe/trunk/include/clang/Driver/ToolChain.h Mon Sep 15 12:19:16 2014
> @@ -248,6 +248,9 @@ public:
>    /// UseSjLjExceptions - Does this tool chain use SjLj exceptions.
>    virtual bool UseSjLjExceptions() const { return false; }
>
> +  /// UseSEHExceptions - Does this tool chain use SEH exceptions.
> +  virtual bool UseSEHExceptions() const { return false; }
> +
>    /// ComputeLLVMTriple - Return the LLVM target triple to use, after
> taking
>    /// command line arguments into account.
>    virtual std::string
>
> Modified: cfe/trunk/lib/CodeGen/CGException.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGException.cpp?rev=217790&r1=217789&r2=217790&view=diff
>
> ==============================================================================
> --- cfe/trunk/lib/CodeGen/CGException.cpp (original)
> +++ cfe/trunk/lib/CodeGen/CGException.cpp Mon Sep 15 12:19:16 2014
> @@ -137,12 +137,14 @@ namespace {
>      static const EHPersonality &get(const LangOptions &Lang);
>      static const EHPersonality GNU_C;
>      static const EHPersonality GNU_C_SJLJ;
> +    static const EHPersonality GNU_C_SEH;
>      static const EHPersonality GNU_ObjC;
>      static const EHPersonality GNUstep_ObjC;
>      static const EHPersonality GNU_ObjCXX;
>      static const EHPersonality NeXT_ObjC;
>      static const EHPersonality GNU_CPlusPlus;
>      static const EHPersonality GNU_CPlusPlus_SJLJ;
> +    static const EHPersonality GNU_CPlusPlus_SEH;
>    };
>  }
>
> @@ -150,12 +152,16 @@ const EHPersonality EHPersonality::GNU_C
>  const EHPersonality
>  EHPersonality::GNU_C_SJLJ = { "__gcc_personality_sj0", nullptr };
>  const EHPersonality
> +EHPersonality::GNU_C_SEH = { "__gcc_personality_seh0", nullptr };
> +const EHPersonality
>  EHPersonality::NeXT_ObjC = { "__objc_personality_v0", nullptr };
>  const EHPersonality
>  EHPersonality::GNU_CPlusPlus = { "__gxx_personality_v0", nullptr };
>  const EHPersonality
>  EHPersonality::GNU_CPlusPlus_SJLJ = { "__gxx_personality_sj0", nullptr };
>  const EHPersonality
> +EHPersonality::GNU_CPlusPlus_SEH = { "__gxx_personality_seh0", nullptr };
> +const EHPersonality
>  EHPersonality::GNU_ObjC = {"__gnu_objc_personality_v0",
> "objc_exception_throw"};
>  const EHPersonality
>  EHPersonality::GNU_ObjCXX = { "__gnustep_objcxx_personality_v0", nullptr
> };
> @@ -165,6 +171,8 @@ EHPersonality::GNUstep_ObjC = { "__gnust
>  static const EHPersonality &getCPersonality(const LangOptions &L) {
>    if (L.SjLjExceptions)
>      return EHPersonality::GNU_C_SJLJ;
> +  if (L.SEHExceptions)
> +    return EHPersonality::GNU_C_SEH;
>    return EHPersonality::GNU_C;
>  }
>
> @@ -189,6 +197,8 @@ static const EHPersonality &getObjCPerso
>  static const EHPersonality &getCXXPersonality(const LangOptions &L) {
>    if (L.SjLjExceptions)
>      return EHPersonality::GNU_CPlusPlus_SJLJ;
> +  else if (L.SEHExceptions)
> +    return EHPersonality::GNU_CPlusPlus_SEH;
>    else
>      return EHPersonality::GNU_CPlusPlus;
>  }
>
> Modified: cfe/trunk/lib/Driver/Tools.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/Tools.cpp?rev=217790&r1=217789&r2=217790&view=diff
>
> ==============================================================================
> --- cfe/trunk/lib/Driver/Tools.cpp (original)
> +++ cfe/trunk/lib/Driver/Tools.cpp Mon Sep 15 12:19:16 2014
> @@ -4112,6 +4112,8 @@ void Clang::ConstructJob(Compilation &C,
>
>    if (getToolChain().UseSjLjExceptions())
>      CmdArgs.push_back("-fsjlj-exceptions");
> +  else if (getToolChain().UseSEHExceptions())
> +    CmdArgs.push_back("-fseh-exceptions");
>
>    // C++ "sane" operator new.
>    if (!Args.hasFlag(options::OPT_fassume_sane_operator_new,
>
> Modified: cfe/trunk/lib/Frontend/CompilerInvocation.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/CompilerInvocation.cpp?rev=217790&r1=217789&r2=217790&view=diff
>
> ==============================================================================
> --- cfe/trunk/lib/Frontend/CompilerInvocation.cpp (original)
> +++ cfe/trunk/lib/Frontend/CompilerInvocation.cpp Mon Sep 15 12:19:16 2014
> @@ -1431,6 +1431,7 @@ static void ParseLangArgs(LangOptions &O
>    Opts.ObjCExceptions = Args.hasArg(OPT_fobjc_exceptions);
>    Opts.CXXExceptions = Args.hasArg(OPT_fcxx_exceptions);
>    Opts.SjLjExceptions = Args.hasArg(OPT_fsjlj_exceptions);
> +  Opts.SEHExceptions = Args.hasArg(OPT_fseh_exceptions);
>    Opts.TraditionalCPP = Args.hasArg(OPT_traditional_cpp);
>
>    Opts.RTTI = !Args.hasArg(OPT_fno_rtti);
>
> Modified: cfe/trunk/lib/Frontend/InitPreprocessor.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/InitPreprocessor.cpp?rev=217790&r1=217789&r2=217790&view=diff
>
> ==============================================================================
> --- cfe/trunk/lib/Frontend/InitPreprocessor.cpp (original)
> +++ cfe/trunk/lib/Frontend/InitPreprocessor.cpp Mon Sep 15 12:19:16 2014
> @@ -556,6 +556,8 @@ static void InitializePredefinedMacros(c
>      Builder.defineMacro("__GXX_RTTI");
>    if (LangOpts.SjLjExceptions)
>      Builder.defineMacro("__USING_SJLJ_EXCEPTIONS__");
> +  if (LangOpts.SEHExceptions)
> +    Builder.defineMacro("__SEH__");
>
>    if (LangOpts.Deprecated)
>      Builder.defineMacro("__DEPRECATED");
>
> Added: cfe/trunk/test/CodeGenCXX/mingw-w64-seh-exceptions.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/mingw-w64-seh-exceptions.cpp?rev=217790&view=auto
>
> ==============================================================================
> --- cfe/trunk/test/CodeGenCXX/mingw-w64-seh-exceptions.cpp (added)
> +++ cfe/trunk/test/CodeGenCXX/mingw-w64-seh-exceptions.cpp Mon Sep 15
> 12:19:16 2014
> @@ -0,0 +1,19 @@
> +// RUN: %clang_cc1 %s -fexceptions -fseh-exceptions -emit-llvm -triple
> x86_64-w64-windows-gnu -o - | FileCheck %s
> +
> +extern "C" void foo();
> +extern "C" void bar();
> +
> +struct Cleanup {
> +  ~Cleanup() {
> +    bar();
> +  }
> +};
> +
> +extern "C" void test() {
> +  Cleanup x;
> +  foo();
> +}
> +
> +// CHECK: define void @test()
> +// CHECK: invoke void @foo()
> +// CHECK: landingpad { i8*, i32 } personality i8* bitcast (i32 (...)*
> @__gxx_personality_seh0 to i8*)
>
>
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20140915/77a835d8/attachment.html>


More information about the cfe-commits mailing list