From: David Majnemer Date: Tue, 9 Dec 2014 00:12:30 +0000 (+0000) Subject: Revert "Driver: Objective-C should respect -fno-exceptions" X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=0a2e4f2c129edc8a3f0590493fd88e5751de60c4;p=clang Revert "Driver: Objective-C should respect -fno-exceptions" This reverts commit r223455. It's been succesfully argued that -fexceptions (at the driver level) is a misnomer and has little to do with -fobjc-exceptions. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@223723 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Driver/Tools.cpp b/lib/Driver/Tools.cpp index 9924bb8896..151d87b50d 100644 --- a/lib/Driver/Tools.cpp +++ b/lib/Driver/Tools.cpp @@ -1894,6 +1894,23 @@ 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) { @@ -1930,21 +1947,15 @@ static void addExceptionArgs(const ArgList &Args, types::ID InputType, // Gather the exception settings from the command line arguments. bool EH = exceptionSettings(Args, Triple); - 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); - - if (ObjCExceptionsEnabled) { - CmdArgs.push_back("-fobjc-exceptions"); + // 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"); - EH = true; - } + EH |= shouldUseExceptionTablesForObjCExceptions(objcRuntime, Triple); } if (types::isCXX(InputType)) { diff --git a/test/Driver/exceptions.m b/test/Driver/exceptions.m new file mode 100644 index 0000000000..9b747bb84d --- /dev/null +++ b/test/Driver/exceptions.m @@ -0,0 +1,19 @@ +// 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 deleted file mode 100644 index 1d918cf39b..0000000000 --- a/test/Driver/exceptions.mm +++ /dev/null @@ -1,6 +0,0 @@ -// 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" diff --git a/test/Driver/rewrite-legacy-objc.m b/test/Driver/rewrite-legacy-objc.m index ceb654f946..b0b78d0081 100644 --- a/test/Driver/rewrite-legacy-objc.m +++ b/test/Driver/rewrite-legacy-objc.m @@ -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" "-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" +// 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"