]> granicus.if.org Git - clang/commitdiff
Driver: Objective-C should respect -fno-exceptions
authorDavid Majnemer <david.majnemer@gmail.com>
Fri, 5 Dec 2014 08:56:55 +0000 (08:56 +0000)
committerDavid Majnemer <david.majnemer@gmail.com>
Fri, 5 Dec 2014 08:56:55 +0000 (08:56 +0000)
Clang attempted to replicate a GCC bug: -fobjc-exceptions forces
-fexceptions to be enabled.  However, this has unintended effects and
other awkard side effects that Clang doesn't "correctly" ape (e.g. it's
impossible to turn off C++ exceptions in ObjC++ mode).

Instead, -f[no]objc-exceptions and -f[no]cxx-exceptions now have an
identical relationship with -f[no]exceptions.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@223455 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Driver/Tools.cpp
test/Driver/exceptions.m [deleted file]
test/Driver/exceptions.mm [new file with mode: 0644]
test/Driver/rewrite-legacy-objc.m

index 151d87b50defc599e107cdedc6508c666da9979a..9924bb8896d557574c9a163e6c294984115015d8 100644 (file)
@@ -1894,23 +1894,6 @@ static void getTargetFeatures(const Driver &D, const llvm::Triple &Triple,
   }
 }
 
-static bool
-shouldUseExceptionTablesForObjCExceptions(const ObjCRuntime &runtime,
-                                          const llvm::Triple &Triple) {
-  // We use the zero-cost exception tables for Objective-C if the non-fragile
-  // ABI is enabled or when compiling for x86_64 and ARM on Snow Leopard and
-  // later.
-  if (runtime.isNonFragile())
-    return true;
-
-  if (!Triple.isMacOSX())
-    return false;
-
-  return (!Triple.isMacOSXVersionLT(10,5) &&
-          (Triple.getArch() == llvm::Triple::x86_64 ||
-           Triple.getArch() == llvm::Triple::arm));
-}
-
 // exceptionSettings() exists to share the logic between -cc1 and linker
 // invocations.
 static bool exceptionSettings(const ArgList &Args, const llvm::Triple &Triple) {
@@ -1947,15 +1930,21 @@ static void addExceptionArgs(const ArgList &Args, types::ID InputType,
   // Gather the exception settings from the command line arguments.
   bool EH = exceptionSettings(Args, Triple);
 
-  // Obj-C exceptions are enabled by default, regardless of -fexceptions. This
-  // is not necessarily sensible, but follows GCC.
-  if (types::isObjC(InputType) &&
-      Args.hasFlag(options::OPT_fobjc_exceptions,
-                   options::OPT_fno_objc_exceptions,
-                   true)) {
-    CmdArgs.push_back("-fobjc-exceptions");
+  if (types::isObjC(InputType)) {
+    bool ObjCExceptionsEnabled = true;
+    if (Arg *A = Args.getLastArg(options::OPT_fobjc_exceptions,
+                                 options::OPT_fno_objc_exceptions,
+                                 options::OPT_fexceptions,
+                                 options::OPT_fno_exceptions))
+      ObjCExceptionsEnabled =
+          A->getOption().matches(options::OPT_fobjc_exceptions) ||
+          A->getOption().matches(options::OPT_fexceptions);
 
-    EH |= shouldUseExceptionTablesForObjCExceptions(objcRuntime, Triple);
+    if (ObjCExceptionsEnabled) {
+      CmdArgs.push_back("-fobjc-exceptions");
+
+      EH = true;
+    }
   }
 
   if (types::isCXX(InputType)) {
diff --git a/test/Driver/exceptions.m b/test/Driver/exceptions.m
deleted file mode 100644 (file)
index 9b747bb..0000000
+++ /dev/null
@@ -1,19 +0,0 @@
-// RUN: %clang -target x86_64-apple-darwin9 \
-// RUN:   -fsyntax-only -fno-exceptions %s
-
-void f1() {
-  @throw @"A";
-}
-
-void f0() {
-  @try {
-    f1();
-  } @catch (id x) {
-    ;
-  }
-}
-
-int main() {
-  f0();
-  return 0;
-}
diff --git a/test/Driver/exceptions.mm b/test/Driver/exceptions.mm
new file mode 100644 (file)
index 0000000..1d918cf
--- /dev/null
@@ -0,0 +1,6 @@
+// RUN: %clang -target x86_64-apple-darwin11 -fno-exceptions %s -o - -### 2>&1 | \
+// RUN:   FileCheck %s
+
+CHECK-NOT: "-fobjc-exceptions"
+CHECK-NOT: "-fcxx-exceptions"
+CHECK-NOT: "-fexceptions"
index b0b78d00817a272f13c56969a86fa35709305455..ceb654f946dd45af66a13d771e8c008611b0124c 100644 (file)
@@ -9,5 +9,5 @@
 // RUN:   FileCheck -check-prefix=TEST1 %s
 // RUN: %clang -no-canonical-prefixes -target i386-apple-macosx10.6.0 -rewrite-legacy-objc %s -o - -### 2>&1 | \
 // RUN:   FileCheck -check-prefix=TEST2 %s
-// TEST1: "-fmessage-length" "0" "-stack-protector" "1" "-mstackrealign" "-fblocks" "-fobjc-runtime=macosx-fragile" "-fobjc-subscripting-legacy-runtime" "-fencode-extended-block-signature" "-fno-objc-infer-related-result-type" "-fobjc-exceptions" "-fmax-type-align=16" "-fdiagnostics-show-option"
-// TEST2: "-fmessage-length" "0" "-stack-protector" "1" "-mstackrealign" "-fblocks" "-fobjc-runtime=macosx-fragile" "-fencode-extended-block-signature" "-fno-objc-infer-related-result-type" "-fobjc-exceptions" "-fmax-type-align=16" "-fdiagnostics-show-option"
+// TEST1: "-fmessage-length" "0" "-stack-protector" "1" "-mstackrealign" "-fblocks" "-fobjc-runtime=macosx-fragile" "-fobjc-subscripting-legacy-runtime" "-fencode-extended-block-signature" "-fno-objc-infer-related-result-type" "-fobjc-exceptions" "-fexceptions" "-fmax-type-align=16" "-fdiagnostics-show-option"
+// TEST2: "-fmessage-length" "0" "-stack-protector" "1" "-mstackrealign" "-fblocks" "-fobjc-runtime=macosx-fragile" "-fencode-extended-block-signature" "-fno-objc-infer-related-result-type" "-fobjc-exceptions" "-fexceptions" "-fmax-type-align=16" "-fdiagnostics-show-option"