diff mbox

[ObjC,ObjC++,Darwin] Remove "-fobjc-sjlj-exceptions"

Message ID 3F3F586F-6A1E-42DB-9A5D-CB9AF39217A7@codesourcery.com
State New
Headers show

Commit Message

Iain Sandoe Nov. 3, 2013, 8:58 p.m. UTC
The Objective C/C++ exceptions model is, currently, completely determined by the combination of runtime {gnu, next} and ABI {m32/V1, m64/V2}.

Thus, the "-fobjc-sjlj-exceptions" command line option is redundant and may be removed.
(note that trunk clang doesn't even accept the option, although xcode 4.6.3 still does).

The patch below removes the action of the flag, and produces a warning if the User puts it on a c/l.

This has been in use for some time on my *-darwin* systems and has been tested also on x86_64-linux. 
 
The option is apparently undocumented in the current User's manual, hence, there are no adjustments to documentation.

OK for trunk?
Iain

gcc/c-family:

	* c-opts.c (c_common_post_options): Remove handling of
	flag_objc_sjlj_exceptions.
	* c.opt (fobjc-sjlj-exceptions): Issue a warning if this
	option is given.

gcc:
	* config/darwin.c (darwin_override_options): Remove handling
	of flag_objc_sjlj_exceptions.

gcc/objc:

	* objc-act.c (objc_begin_try_stmt): Find the exceptions model
	in force from the runtime structure rather than a command line
	flag.
	* objc-gnu-runtime-abi-01.c (objc_gnu_runtime_abi_01_init): Set
	up the exceptions model and handle conflicting User selections.
	* objc-next-runtime-abi-02.c (objc_next_runtime_abi_02_init): 
	Likewise.
	* objc-next-runtime-abi-01.c (OBJC_SJLJ_EXCEPTIONS): Define true.
	(objc_next_runtime_abi_01_init): Set up the exceptions model and
	 handle conflicting User selections.
	(next_runtime_01_initialize, objc_build_exc_ptr, finish_try_stmt): 
	Use OBJC_SJLJ_EXCEPTIONS rather than a flag.
	* objc-runtime-hooks.h (objc_exceptions_model_t): New enum.
	(objc_runtime_hooks): Add exceptions model.
gcc/c-family/c-opts.c               |  6 ------
 gcc/c-family/c.opt                  |  4 ++--
 gcc/config/darwin.c                 | 12 ------------
 gcc/objc/objc-act.c                 |  2 +-
 gcc/objc/objc-gnu-runtime-abi-01.c  | 18 +++++++++++++-----
 gcc/objc/objc-next-runtime-abi-01.c | 20 ++++++++++----------
 gcc/objc/objc-next-runtime-abi-02.c | 20 +++++++++++++++-----
 gcc/objc/objc-runtime-hooks.h       | 12 ++++++++++++
 8 files changed, 53 insertions(+), 41 deletions(-)

Comments

Gerald Pfeifer Nov. 3, 2013, 10:16 p.m. UTC | #1
Hi Ian,

On Sun, 3 Nov 2013, Iain Sandoe wrote:
> The option is apparently undocumented in the current User's manual, 
> hence, there are no adjustments to documentation.

I cannot approve the patch, but if it goes in that way or a similar 
one I recommend to add a short note to htdocs/gcc-4.9/changes.html,
just for those who may be using it.

Gerald
Mike Stump Nov. 4, 2013, 3:49 a.m. UTC | #2
On Nov 3, 2013, at 12:58 PM, Iain Sandoe <iain@codesourcery.com> wrote:
> The Objective C/C++ exceptions model is, currently, completely determined by the combination of runtime {gnu, next} and ABI {m32/V1, m64/V2}.

> OK for trunk?

Ok.
Joseph Myers Nov. 4, 2013, 6:28 p.m. UTC | #3
On Sun, 3 Nov 2013, Iain Sandoe wrote:

> gcc/c-family:
> 
> 	* c-opts.c (c_common_post_options): Remove handling of
> 	flag_objc_sjlj_exceptions.
> 	* c.opt (fobjc-sjlj-exceptions): Issue a warning if this
> 	option is given.

The c-family changes are OK.
diff mbox

Patch

diff --git a/gcc/c-family/c-opts.c b/gcc/c-family/c-opts.c
index 702fe1a..9d0b972 100644
--- a/gcc/c-family/c-opts.c
+++ b/gcc/c-family/c-opts.c
@@ -834,12 +834,6 @@  c_common_post_options (const char **pfilename)
   else if (!flag_gnu89_inline && !flag_isoc99)
     error ("-fno-gnu89-inline is only supported in GNU99 or C99 mode");
 
-  /* Default to ObjC sjlj exception handling if NeXT runtime.  */
-  if (flag_objc_sjlj_exceptions < 0)
-    flag_objc_sjlj_exceptions = flag_next_runtime;
-  if (flag_objc_exceptions && !flag_objc_sjlj_exceptions)
-    flag_exceptions = 1;
-
   /* -Woverlength-strings is off by default, but is enabled by -Wpedantic.
      It is never enabled in C++, as the minimum limit is not normative
      in that standard.  */
diff --git a/gcc/c-family/c.opt b/gcc/c-family/c.opt
index b862eb9..23646f3 100644
--- a/gcc/c-family/c.opt
+++ b/gcc/c-family/c.opt
@@ -1058,8 +1058,8 @@  Enable inline checks for nil receivers with the NeXT runtime and ABI version 2.
 
 ; Nonzero means that we generate NeXT setjmp based exceptions.
 fobjc-sjlj-exceptions
-ObjC ObjC++ Var(flag_objc_sjlj_exceptions) Init(-1)
-Enable Objective-C setjmp exception handling runtime
+ObjC ObjC++ Ignore Warn(switch %qs has been removed and is set automatically where required)
+Option removed
 
 fobjc-std=objc1
 ObjC ObjC++ Var(flag_objc1_only)
diff --git a/gcc/config/darwin.c b/gcc/config/darwin.c
index fc7a9a8..3bf30db 100644
--- a/gcc/config/darwin.c
+++ b/gcc/config/darwin.c
@@ -3126,18 +3126,6 @@  darwin_override_options (void)
       flag_reorder_blocks = 1;
     }
 
-    /* FIXME: flag_objc_sjlj_exceptions is no longer needed since there is only
-       one valid choice of exception scheme for each runtime.  */
-    if (!global_options_set.x_flag_objc_sjlj_exceptions)
-      global_options.x_flag_objc_sjlj_exceptions = 
-				flag_next_runtime && !TARGET_64BIT;
-
-    /* FIXME: and this could be eliminated then too.  */
-    if (!global_options_set.x_flag_exceptions
-	&& flag_objc_exceptions
-	&& TARGET_64BIT)
-      flag_exceptions = 1;
-
   if (flag_mkernel || flag_apple_kext)
     {
       /* -mkernel implies -fapple-kext for C++ */
diff --git a/gcc/objc/objc-act.c b/gcc/objc/objc-act.c
index 95ec4ec..6103b3b 100644
--- a/gcc/objc/objc-act.c
+++ b/gcc/objc/objc-act.c
@@ -4126,7 +4126,7 @@  objc_begin_try_stmt (location_t try_locus, tree body)
   /* Collect the list of local variables.  We'll mark them as volatile
      at the end of compilation of this function to prevent them being
      clobbered by setjmp/longjmp.  */
-  if (flag_objc_sjlj_exceptions)
+  if (runtime.exceptions_model == objc_exceptions_sjlj)
     objc_mark_locals_volatile (NULL);
 }
 
diff --git a/gcc/objc/objc-gnu-runtime-abi-01.c b/gcc/objc/objc-gnu-runtime-abi-01.c
index f011683..fdcd409 100644
--- a/gcc/objc/objc-gnu-runtime-abi-01.c
+++ b/gcc/objc/objc-gnu-runtime-abi-01.c
@@ -132,12 +132,20 @@  objc_gnu_runtime_abi_01_init (objc_runtime_hooks *rthooks)
       flag_objc_gc = 0;
     }
 
-  /* Although I guess we could, we don't currently support SJLJ exceptions for the
-     GNU runtime.  */
-  if (flag_objc_sjlj_exceptions)
+  /* Objective C exceptions implies -fexceptions for the GNU Runtime.  */
+  if (flag_objc_exceptions)
     {
-      inform (UNKNOWN_LOCATION, "%<-fobjc-sjlj-exceptions%> is ignored for %<-fgnu-runtime%>");
-      flag_objc_sjlj_exceptions = 0;
+      /* GNU runtime uses dwarf unwinding.  */
+      rthooks->exceptions_model = objc_exceptions_dwarf;
+
+      /* If the User has not specified fexceptions, set it silently.  */
+      if (!global_options_set.x_flag_exceptions)
+	flag_exceptions = 1;
+      else if (!flag_exceptions)
+        /* If the User has explicitly specified -fno-exceptions together
+           with -fobjc-exceptions, this is an error.  */
+        error_at (UNKNOWN_LOCATION, "%<-fobjc-exceptions%> requires"
+				    "%<-fexceptions%> for the GNU runtime");
     }
 
   /* TODO: Complain if -fobjc-abi-version=N was used.  */
diff --git a/gcc/objc/objc-next-runtime-abi-01.c b/gcc/objc/objc-next-runtime-abi-01.c
index 000256d..dcaa0d7 100644
--- a/gcc/objc/objc-next-runtime-abi-01.c
+++ b/gcc/objc/objc-next-runtime-abi-01.c
@@ -97,6 +97,9 @@  along with GCC; see the file COPYING3.  If not see
 
 #define CLS_HAS_CXX_STRUCTORS		0x2000L
 
+/* For this ABI, there is no choice but to use sjlj, presently.  */
+#define OBJC_SJLJ_EXCEPTIONS true
+
 /* rt_trees identifiers - shared between NeXT implementations.  These
    allow the FE to tag meta-data in a manner that survives LTO and can
    be used when the runtime requires that certain meta-data items
@@ -144,13 +147,9 @@  static tree finish_try_stmt (struct objc_try_context **);
 bool
 objc_next_runtime_abi_01_init (objc_runtime_hooks *rthooks)
 {
-  if (flag_objc_exceptions
-      && !flag_objc_sjlj_exceptions)
-    {
-      warning_at (UNKNOWN_LOCATION, OPT_Wall,
-		"%<-fobjc-sjlj-exceptions%> is the only supported exceptions "
-		"system for %<-fnext-runtime%> with %<-fobjc-abi-version%> < 2");
-    }
+  /* NeXT V0/1 Objective-C and Objective-C++ exceptions (i.e. @throw) are
+     SjLj exceptions.  */
+  rthooks->exceptions_model = objc_exceptions_sjlj;
 
   rthooks->initialize = next_runtime_01_initialize;
   rthooks->default_constant_string_class_name = DEF_CONSTANT_STRING_CLASS_NAME;
@@ -383,7 +382,7 @@  static void next_runtime_01_initialize (void)
   objc_setPropertyStruct_decl = NULL_TREE;
 
   build_next_objc_exception_stuff ();
-  if (flag_objc_exceptions && !flag_objc_sjlj_exceptions)
+  if (flag_objc_exceptions && !OBJC_SJLJ_EXCEPTIONS)
     using_eh_for_cleanups ();
   lang_hooks.eh_runtime_type = objc_eh_runtime_type;
   lang_hooks.eh_personality = objc_eh_personality;
@@ -2847,6 +2846,7 @@  objc_eh_personality (void)
 {
   if (!objc_eh_personality_decl)
 #ifndef OBJCPLUS
+    /* The personality for ABI=0,1 is just the gcc one.  */
     objc_eh_personality_decl = build_personality_function ("gcc");
 #else
     objc_eh_personality_decl = build_personality_function ("gxx");
@@ -2877,7 +2877,7 @@  build_throw_stmt (location_t loc, tree throw_expr, bool rethrown ATTRIBUTE_UNUSE
 static tree
 objc_build_exc_ptr (struct objc_try_context **cur_try_context)
 {
-  if (flag_objc_sjlj_exceptions)
+  if (OBJC_SJLJ_EXCEPTIONS)
     {
       tree var = (*cur_try_context)->caught_decl;
       if (!var)
@@ -2925,7 +2925,7 @@  finish_try_stmt (struct objc_try_context **cur_try_context)
   tree stmt;
   struct objc_try_context *c = *cur_try_context;
   /* If we're doing Darwin setjmp exceptions, build the big nasty.  */
-  if (flag_objc_sjlj_exceptions)
+  if (OBJC_SJLJ_EXCEPTIONS)
     {
       bool save = in_late_binary_op;
       in_late_binary_op = true;
diff --git a/gcc/objc/objc-next-runtime-abi-02.c b/gcc/objc/objc-next-runtime-abi-02.c
index 0960006..8762a6f 100644
--- a/gcc/objc/objc-next-runtime-abi-02.c
+++ b/gcc/objc/objc-next-runtime-abi-02.c
@@ -239,11 +239,20 @@  objc_next_runtime_abi_02_init (objc_runtime_hooks *rthooks)
 {
   extern_names = ggc_alloc_cleared_vec_hash (SIZEHASHTABLE);
 
-  if (flag_objc_exceptions && flag_objc_sjlj_exceptions)
+  if (flag_objc_exceptions)
     {
-      inform (UNKNOWN_LOCATION, "%<-fobjc-sjlj-exceptions%> is ignored for "
-				"%<-fnext-runtime%> when %<-fobjc-abi-version%> >= 2");
-      flag_objc_sjlj_exceptions = 0;
+      /* NeXT ABI v2 runtime uses dwarf unwinding.  */
+      rthooks->exceptions_model = objc_exceptions_dwarf;
+
+      /* If the User has not specified fexceptions, set it silently.  */
+      if (!global_options_set.x_flag_exceptions)
+	flag_exceptions = 1;
+      else if (!flag_exceptions)
+        /* If the User has explicitly specified -fno-exceptions together
+           with -fobjc-exceptions, this is an error.  */
+        error_at (UNKNOWN_LOCATION, "%<-fobjc-exceptions%> requires"
+				    "%<-fexceptions%> for the 64 bit NeXT"
+				    " runtime");
     }
 
   rthooks->initialize = next_runtime_02_initialize;
@@ -478,7 +487,8 @@  static void next_runtime_02_initialize (void)
   objc_getPropertyStruct_decl = NULL_TREE;
   objc_setPropertyStruct_decl = NULL_TREE;
 
-  gcc_assert (!flag_objc_sjlj_exceptions);
+  gcc_checking_assert (!flag_objc_exceptions
+		       || (runtime.exceptions_model == objc_exceptions_dwarf));
 
   /* Although we warn that fobjc-exceptions is required for exceptions
      code, we carry on and create it anyway.  */
diff --git a/gcc/objc/objc-runtime-hooks.h b/gcc/objc/objc-runtime-hooks.h
index c6de986..badf899 100644
--- a/gcc/objc/objc-runtime-hooks.h
+++ b/gcc/objc/objc-runtime-hooks.h
@@ -33,6 +33,15 @@  along with GCC; see the file COPYING3.  If not see
    and so on, and the purpose of this interface is to abstract such
    differences from the parser's perspective.  */
 
+/* Currently, two different exceptions models are used (depends on which
+   runtime and ABI is selected).  */
+
+typedef enum {
+  objc_exceptions_unk = 0,
+  objc_exceptions_sjlj,
+  objc_exceptions_dwarf
+} objc_exceptions_model_t;
+
 /* TODO: Do we want the initial underscore ? */
 typedef struct _objc_runtime_hooks_r
 {
@@ -97,6 +106,9 @@  typedef struct _objc_runtime_hooks_r
      during parsing.  */
   void (*generate_metadata) (void);
 
+  /* What kind of exceptions code to generate.  */
+  objc_exceptions_model_t exceptions_model;
+
 } objc_runtime_hooks;
 
 /* For shared support that needs to access these.  */