On Fri, Dec 5, 2014 at 11:41 AM, David Majnemer <[email protected]> wrote:
> > > On Fri, Dec 5, 2014 at 11:25 AM, Nico Weber <[email protected]> wrote: > >> On Fri, Dec 5, 2014 at 12:56 AM, David Majnemer <[email protected] >> > wrote: >> >>> Author: majnemer >>> Date: Fri Dec 5 02:56:55 2014 >>> New Revision: 223455 >>> >>> URL: http://llvm.org/viewvc/llvm-project?rev=223455&view=rev >>> Log: >>> Driver: Objective-C should respect -fno-exceptions >>> >>> 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 >> >> >> What does "impossible to turn off exceptions" mean here? >> >> $ clang -c test.mm -fno-exceptions >> test.mm:2:3: error: cannot use 'try' with exceptions disabled >> try {} catch (...) {} >> ^ >> 1 error generated. >> > > You should try that with GCC, not clang :) > > >> >> ). >>> >>> Instead, -f[no]objc-exceptions and -f[no]cxx-exceptions now have an >>> identical relationship with -f[no]exceptions. >>> >> >> Did anyone from Apple review this? I thought the intention was that >> -fno-exceptions disables c++ exceptions but keeps objc exceptions enabled, >> since a) many people don't want c++ exceptions so they use -fno-exceptions >> but b) cocoa uses exceptions so you can't really build without objc >> exceptions. >> >> (I'm guessing I'm misunderstanding the patch somehow.) >> > > The original code was trying to mimic GCC's behavior where > -fobjc-exceptions _ignores_ -fno-exceptions. > In GCC, this means that ObjC++ code cannot _ever_ opt out of C++ > exceptions because they don't have a -fcxx-exceptions, they just have > -fexceptions. Clang has a different dichotomy of exception > enabling/disabling flags and it doesn't make sense to copy GCC's arbitrary > behavior. > > If you want Objective-C exceptions but not C++ exceptions, > -fobjc-exceptions -fno-cxx-exceptions should do the trick. > I'm somewhat sure that when these flags got added they were explicitly put in a state where -fno-exceptions disables c++ exceptions but not objc exceptions, for the reason I mentioned above. I don't remember anything about gcc compatibility. Most software doesn't use Objective-C, and when folks say -fno-exceptions they mean "no c++ exceptions". > > >> >>> >>> Added: >>> cfe/trunk/test/Driver/exceptions.mm >>> Removed: >>> cfe/trunk/test/Driver/exceptions.m >>> Modified: >>> cfe/trunk/lib/Driver/Tools.cpp >>> cfe/trunk/test/Driver/rewrite-legacy-objc.m >>> >>> Modified: cfe/trunk/lib/Driver/Tools.cpp >>> URL: >>> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/Tools.cpp?rev=223455&r1=223454&r2=223455&view=diff >>> >>> ============================================================================== >>> --- cfe/trunk/lib/Driver/Tools.cpp (original) >>> +++ cfe/trunk/lib/Driver/Tools.cpp Fri Dec 5 02:56:55 2014 >>> @@ -1894,23 +1894,6 @@ static void getTargetFeatures(const Driv >>> } >>> } >>> >>> -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 ArgLi >>> // 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); >>> + >>> + if (ObjCExceptionsEnabled) { >>> + CmdArgs.push_back("-fobjc-exceptions"); >>> >>> - EH |= shouldUseExceptionTablesForObjCExceptions(objcRuntime, >>> Triple); >>> + EH = true; >>> + } >>> } >>> >>> if (types::isCXX(InputType)) { >>> >>> Removed: cfe/trunk/test/Driver/exceptions.m >>> URL: >>> http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/exceptions.m?rev=223454&view=auto >>> >>> ============================================================================== >>> --- cfe/trunk/test/Driver/exceptions.m (original) >>> +++ cfe/trunk/test/Driver/exceptions.m (removed) >>> @@ -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; >>> -} >>> >>> Added: cfe/trunk/test/Driver/exceptions.mm >>> URL: >>> http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/exceptions.mm?rev=223455&view=auto >>> >>> ============================================================================== >>> --- cfe/trunk/test/Driver/exceptions.mm (added) >>> +++ cfe/trunk/test/Driver/exceptions.mm Fri Dec 5 02:56:55 2014 >>> @@ -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" >>> >>> Modified: cfe/trunk/test/Driver/rewrite-legacy-objc.m >>> URL: >>> http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/rewrite-legacy-objc.m?rev=223455&r1=223454&r2=223455&view=diff >>> >>> ============================================================================== >>> --- cfe/trunk/test/Driver/rewrite-legacy-objc.m (original) >>> +++ cfe/trunk/test/Driver/rewrite-legacy-objc.m Fri Dec 5 02:56:55 2014 >>> @@ -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" >>> >>> >>> _______________________________________________ >>> cfe-commits mailing list >>> [email protected] >>> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits >>> >> >> > > On Fri, Dec 5, 2014 at 11:25 AM, Nico Weber <[email protected]> wrote: > >> On Fri, Dec 5, 2014 at 12:56 AM, David Majnemer <[email protected] >> > wrote: >> >>> Author: majnemer >>> Date: Fri Dec 5 02:56:55 2014 >>> New Revision: 223455 >>> >>> URL: http://llvm.org/viewvc/llvm-project?rev=223455&view=rev >>> Log: >>> Driver: Objective-C should respect -fno-exceptions >>> >>> 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 >> >> >> What does "impossible to turn off exceptions" mean here? >> >> $ clang -c test.mm -fno-exceptions >> test.mm:2:3: error: cannot use 'try' with exceptions disabled >> try {} catch (...) {} >> ^ >> 1 error generated. >> >> ). >>> >>> Instead, -f[no]objc-exceptions and -f[no]cxx-exceptions now have an >>> identical relationship with -f[no]exceptions. >>> >> >> Did anyone from Apple review this? I thought the intention was that >> -fno-exceptions disables c++ exceptions but keeps objc exceptions enabled, >> since a) many people don't want c++ exceptions so they use -fno-exceptions >> but b) cocoa uses exceptions so you can't really build without objc >> exceptions. >> >> (I'm guessing I'm misunderstanding the patch somehow.) >> >> >>> >>> Added: >>> cfe/trunk/test/Driver/exceptions.mm >>> Removed: >>> cfe/trunk/test/Driver/exceptions.m >>> Modified: >>> cfe/trunk/lib/Driver/Tools.cpp >>> cfe/trunk/test/Driver/rewrite-legacy-objc.m >>> >>> Modified: cfe/trunk/lib/Driver/Tools.cpp >>> URL: >>> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/Tools.cpp?rev=223455&r1=223454&r2=223455&view=diff >>> >>> ============================================================================== >>> --- cfe/trunk/lib/Driver/Tools.cpp (original) >>> +++ cfe/trunk/lib/Driver/Tools.cpp Fri Dec 5 02:56:55 2014 >>> @@ -1894,23 +1894,6 @@ static void getTargetFeatures(const Driv >>> } >>> } >>> >>> -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 ArgLi >>> // 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); >>> + >>> + if (ObjCExceptionsEnabled) { >>> + CmdArgs.push_back("-fobjc-exceptions"); >>> >>> - EH |= shouldUseExceptionTablesForObjCExceptions(objcRuntime, >>> Triple); >>> + EH = true; >>> + } >>> } >>> >>> if (types::isCXX(InputType)) { >>> >>> Removed: cfe/trunk/test/Driver/exceptions.m >>> URL: >>> http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/exceptions.m?rev=223454&view=auto >>> >>> ============================================================================== >>> --- cfe/trunk/test/Driver/exceptions.m (original) >>> +++ cfe/trunk/test/Driver/exceptions.m (removed) >>> @@ -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; >>> -} >>> >>> Added: cfe/trunk/test/Driver/exceptions.mm >>> URL: >>> http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/exceptions.mm?rev=223455&view=auto >>> >>> ============================================================================== >>> --- cfe/trunk/test/Driver/exceptions.mm (added) >>> +++ cfe/trunk/test/Driver/exceptions.mm Fri Dec 5 02:56:55 2014 >>> @@ -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" >>> >>> Modified: cfe/trunk/test/Driver/rewrite-legacy-objc.m >>> URL: >>> http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/rewrite-legacy-objc.m?rev=223455&r1=223454&r2=223455&view=diff >>> >>> ============================================================================== >>> --- cfe/trunk/test/Driver/rewrite-legacy-objc.m (original) >>> +++ cfe/trunk/test/Driver/rewrite-legacy-objc.m Fri Dec 5 02:56:55 2014 >>> @@ -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" >>> >>> >>> _______________________________________________ >>> cfe-commits mailing list >>> [email protected] >>> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits >>> >> >> >
_______________________________________________ cfe-commits mailing list [email protected] http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
