Switch to using -fsjlj-exceptions instead of hard-coding it. Notably, this fixes
calls to the UnwindResumeOrRethrow function for C++/Obj-C exception handling,
for Darwin ARM.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@95787 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Driver/ToolChains.cpp b/lib/Driver/ToolChains.cpp
index a00d8d9..a7cd711 100644
--- a/lib/Driver/ToolChains.cpp
+++ b/lib/Driver/ToolChains.cpp
@@ -640,6 +640,12 @@
   return false;
 }
 
+bool Darwin::UseSjLjExceptions() const {
+  // Darwin uses SjLj exceptions on ARM.
+  return (getTriple().getArch() == llvm::Triple::arm ||
+          getTriple().getArch() == llvm::Triple::thumb);
+}
+
 const char *Darwin::GetDefaultRelocationModel() const {
   return "pic";
 }
diff --git a/lib/Driver/ToolChains.h b/lib/Driver/ToolChains.h
index fbb1136..fda0875 100644
--- a/lib/Driver/ToolChains.h
+++ b/lib/Driver/ToolChains.h
@@ -176,6 +176,8 @@
 
   virtual bool UseDwarfDebugFlags() const;
 
+  virtual bool UseSjLjExceptions() const;
+
   /// }
 };
 
diff --git a/lib/Driver/Tools.cpp b/lib/Driver/Tools.cpp
index 2aa7116..7bc7875 100644
--- a/lib/Driver/Tools.cpp
+++ b/lib/Driver/Tools.cpp
@@ -1004,6 +1004,9 @@
   if (needsExceptions(Args, InputType, getToolChain().getTriple()))
     CmdArgs.push_back("-fexceptions");
 
+  if (getToolChain().UseSjLjExceptions())
+    CmdArgs.push_back("-fsjlj-exceptions");
+
   // -frtti is default.
   if (!Args.hasFlag(options::OPT_frtti, options::OPT_fno_rtti))
     CmdArgs.push_back("-fno-rtti");