]> granicus.if.org Git - clang/commitdiff
Switch to using -fsjlj-exceptions instead of hard-coding it. Notably, this fixes
authorDaniel Dunbar <daniel@zuster.org>
Wed, 10 Feb 2010 18:49:11 +0000 (18:49 +0000)
committerDaniel Dunbar <daniel@zuster.org>
Wed, 10 Feb 2010 18:49:11 +0000 (18:49 +0000)
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

include/clang/Driver/ToolChain.h
lib/Basic/Targets.cpp
lib/CodeGen/CGException.cpp
lib/CodeGen/CGObjCMac.cpp
lib/Driver/ToolChains.cpp
lib/Driver/ToolChains.h
lib/Driver/Tools.cpp
lib/Frontend/InitPreprocessor.cpp
test/CodeGenObjC/unwind-fn.m [new file with mode: 0644]

index 669d64263da9843c3401d293e0c643b9e7be7e9d..42b3d47c064bb72dd7895ea1d1ed2d9c13f05552 100644 (file)
@@ -123,6 +123,9 @@ public:
   /// UseDwarfDebugFlags - Embed the compile options to clang into the Dwarf
   /// compile unit information.
   virtual bool UseDwarfDebugFlags() const { return false; }
+
+  /// UseSjLjExceptions - Does this tool chain use SjLj exceptions.
+  virtual bool UseSjLjExceptions() const { return false; };
 };
 
 } // end namespace driver
index cf2edb2b8414cfd2073850606151603ac21b0dad..b96e17d8924336e5c6c617a0f03e0b74b1579407 100644 (file)
@@ -1385,9 +1385,6 @@ public:
     // when Neon instructions are actually available.
     if (FPU == NeonFPU && !SoftFloat && IsThumb2)
       Builder.defineMacro("__ARM_NEON__");
-
-    if (getTriple().getOS() == llvm::Triple::Darwin)
-      Builder.defineMacro("__USING_SJLJ_EXCEPTIONS__");
   }
   virtual void getTargetBuiltins(const Builtin::Info *&Records,
                                  unsigned &NumRecords) const {
index 60a1016cc040b2bb4b11d3b618a73225146bcf99..d956c1c3cd8576bc355e2a2ed2a390b6391dc1fd 100644 (file)
@@ -100,10 +100,6 @@ static llvm::Constant *getUnexpectedFn(CodeGenFunction &CGF) {
   return CGF.CGM.CreateRuntimeFunction(FTy, "__cxa_call_unexpected");
 }
 
-// FIXME: Eventually this will all go into the backend.  Set from the target for
-// now.
-static int using_sjlj_exceptions = 0;
-
 static llvm::Constant *getUnwindResumeOrRethrowFn(CodeGenFunction &CGF) {
   const llvm::Type *Int8PtrTy = llvm::Type::getInt8PtrTy(CGF.getLLVMContext());
   std::vector<const llvm::Type*> Args(1, Int8PtrTy);
@@ -112,7 +108,7 @@ static llvm::Constant *getUnwindResumeOrRethrowFn(CodeGenFunction &CGF) {
     llvm::FunctionType::get(llvm::Type::getVoidTy(CGF.getLLVMContext()), Args,
                             false);
 
-  if (using_sjlj_exceptions)
+  if (CGF.CGM.getLangOptions().SjLjExceptions)
     return CGF.CGM.CreateRuntimeFunction(FTy, "_Unwind_SjLj_Resume");
   return CGF.CGM.CreateRuntimeFunction(FTy, "_Unwind_Resume_or_Rethrow");
 }
index 2f931bd637a5335cd8e9395a201807de61057dd5..b0b1a9fe7cf475cc19c4552139bfb9cc673c766a 100644 (file)
@@ -738,7 +738,8 @@ public:
     return CGM.CreateRuntimeFunction(
       llvm::FunctionType::get(llvm::Type::getVoidTy(VMContext),
                               Params, false),
-      "_Unwind_Resume_or_Rethrow");
+      (CGM.getLangOptions().SjLjExceptions ? "_Unwind_SjLj_Resume" :
+       "_Unwind_Resume_or_Rethrow"));
   }
 
   llvm::Constant *getObjCEndCatchFn() {
index a00d8d9597e3ba1b0eef61917bf1765df8a5660c..a7cd711df1bc9e0516429f3f713f3eded6b00f75 100644 (file)
@@ -640,6 +640,12 @@ bool Darwin::UseDwarfDebugFlags() const {
   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";
 }
index fbb1136199db21c3b208da25069415a8e25626d8..fda08758c9bc0a9198a1354d33d66c1489fa8aa0 100644 (file)
@@ -176,6 +176,8 @@ public:
 
   virtual bool UseDwarfDebugFlags() const;
 
+  virtual bool UseSjLjExceptions() const;
+
   /// }
 };
 
index 2aa71163be62e32c098f977420c5f5fec2d7f307..7bc7875b1132e8f89b96218f4cc13dddb61a578d 100644 (file)
@@ -1004,6 +1004,9 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
   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");
index 9aaf1320346f275703c3c04b49fe6bd1f4764bc5..b7ab3d8cd4523670e2aff0ba6f60baf44ea56583 100644 (file)
@@ -279,6 +279,8 @@ static void InitializePredefinedMacros(const TargetInfo &TI,
 
   if (LangOpts.Exceptions)
     Builder.defineMacro("__EXCEPTIONS");
+  if (LangOpts.SjLjExceptions)
+    Builder.defineMacro("__USING_SJLJ_EXCEPTIONS__");
 
   if (LangOpts.CPlusPlus) {
     Builder.defineMacro("__DEPRECATED");
diff --git a/test/CodeGenObjC/unwind-fn.m b/test/CodeGenObjC/unwind-fn.m
new file mode 100644 (file)
index 0000000..0aa8cde
--- /dev/null
@@ -0,0 +1,14 @@
+// RUN: %clang_cc1 -fobjc-nonfragile-abi -emit-llvm -o - %s | FileCheck --check-prefix=DEFAULT_EH %s
+// RUN: %clang_cc1 -fsjlj-exceptions -fobjc-nonfragile-abi -emit-llvm -o - %s | FileCheck --check-prefix=SJLJ_EH %s
+
+// DEFAULT_EH: declare void @_Unwind_Resume_or_Rethrow(i8*)
+// SJLJ_EH: declare void @_Unwind_SjLj_Resume(i8*)
+
+void f1(), f2();
+void f0() {
+  @try {
+    f1();
+  } @catch (...) {
+    f2();
+  }
+}