public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [Patch ObjC] fix objc.dg/exceptions2.m linkage error.
@ 2010-12-17 15:52 IainS
  2010-12-17 19:03 ` Nicola Pero
  2010-12-17 21:09 ` Mike Stump
  0 siblings, 2 replies; 6+ messages in thread
From: IainS @ 2010-12-17 15:52 UTC (permalink / raw)
  To: GCC Patches; +Cc: Mike Stump, Nicola Pero

[-- Attachment #1: Type: text/plain, Size: 490 bytes --]

The NeXT runtime library names its m64 personality routine  
"___objc_personality_v0"

So, in addition to the change to switch off sjlj exceptions (which  
causes linkage errors for the absent sjlj routines),
we also need to generate the right name for the eh personality...

OK?
Iain

objc:

	* objc/objc-act.c (objc_eh_personality): Select personality name on  
runtime.
	(objc_init_exceptions): New.
	(objc_begin_try_stmt): Use objc_init_exceptions.
	(objc_build_throw_stmt): Likewise.


[-- Attachment #2: 167976-objc-m64-except.txt --]
[-- Type: text/plain, Size: 2635 bytes --]

Index: gcc/objc/objc-act.c
===================================================================
--- gcc/objc/objc-act.c	(revision 167976)
+++ gcc/objc/objc-act.c	(working copy)
@@ -5028,11 +5028,41 @@ tree
 objc_eh_personality (void)
 {
   if (!flag_objc_sjlj_exceptions && !objc_eh_personality_decl)
-    objc_eh_personality_decl = build_personality_function ("gnu_objc");
+    objc_eh_personality_decl = build_personality_function 
+				(flag_next_runtime
+						? "objc"
+						: "gnu_objc");
   return objc_eh_personality_decl;
 }
 #endif
 
+static void
+objc_init_exceptions (location_t loc)
+{
+  static bool done = false;
+
+  /* -fobjc-exceptions is required to enable Objective-C exceptions.
+     For example, on Darwin, ObjC exceptions require a sufficiently
+     recent version of the runtime, so the user must ask for them
+     explicitly.  On other platforms, at the moment -fobjc-exceptions
+     triggers -fexceptions which again is required for exceptions to
+     work.
+  */
+  if (!flag_objc_exceptions)
+    {
+      error_at (loc, "%<-fobjc-exceptions%> is required to enable Objective-C exception syntax");
+    }
+
+  /* We could arrange for only one warning - by moving this before the check.  */
+  if (done)
+    return;
+  done = true;
+
+#ifndef OBJCPLUS
+  using_eh_for_cleanups ();
+#endif
+}
+
 /* Build __builtin_eh_pointer, or the moral equivalent.  In the case
    of Darwin, we'll arrange for it to be initialized (and associated
    with a binding) later.  */
@@ -5334,17 +5364,7 @@ objc_begin_try_stmt (location_t try_locus, tree bo
   c->end_try_locus = input_location;
   cur_try_context = c;
 
-  /* -fobjc-exceptions is required to enable Objective-C exceptions.
-     For example, on Darwin, ObjC exceptions require a sufficiently
-     recent version of the runtime, so the user must ask for them
-     explicitly.  On other platforms, at the moment -fobjc-exceptions
-     triggers -fexceptions which again is required for exceptions to
-     work.
-  */
-  if (!flag_objc_exceptions)
-    {
-      error_at (try_locus, "%<-fobjc-exceptions%> is required to enable Objective-C exception syntax");
-    }
+  objc_init_exceptions (try_locus);
 
   /* Collect the list of local variables.  We'll mark them as volatile
      at the end of compilation of this function to prevent them being
@@ -5552,10 +5572,7 @@ objc_build_throw_stmt (location_t loc, tree throw_
 {
   tree args;
 
-  if (!flag_objc_exceptions)
-    {
-      error_at (loc, "%<-fobjc-exceptions%> is required to enable Objective-C exception syntax");
-    }
+  objc_init_exceptions (loc);
 
   if (throw_expr == NULL)
     {

[-- Attachment #3: Type: text/plain, Size: 3 bytes --]





^ permalink raw reply	[flat|nested] 6+ messages in thread

* RE: [Patch ObjC] fix objc.dg/exceptions2.m linkage error.
  2010-12-17 15:52 [Patch ObjC] fix objc.dg/exceptions2.m linkage error IainS
@ 2010-12-17 19:03 ` Nicola Pero
  2010-12-17 21:09 ` Mike Stump
  1 sibling, 0 replies; 6+ messages in thread
From: Nicola Pero @ 2010-12-17 19:03 UTC (permalink / raw)
  To: IainS; +Cc: GCC Patches, Mike Stump


+  /* We could arrange for only one warning - by moving this before the check.  */

Yes, excellent idea - don't be shy - why don't you just update the patch to do it ? ;-)

I love your idea of printing the error

  "-fobjc-exceptions is required to enable Objective-C exception syntax"

only once per compilation unit instead of a lot of times. :-)

The main problem, I guess, would be updating the tests in the testsuite as
fobjc-exceptions.m would need to be broken down into multiple tests.

But it seems worth it.  It's distracting when the same error is printed lots of times.

Anyway, just a suggestion for making the patch even better; there's nothing wrong with it as it is.

Thanks

-----Original Message-----
From: "IainS" <developer@sandoe-acoustics.co.uk>
Sent: Friday, 17 December, 2010 15:34
To: "GCC Patches" <gcc-patches@gcc.gnu.org>
Cc: "Mike Stump" <mrs@gcc.gnu.org>, "Nicola Pero" <nicola.pero@meta-innovation.com>
Subject: [Patch ObjC] fix objc.dg/exceptions2.m linkage error.

The NeXT runtime library names its m64 personality routine  
"___objc_personality_v0"

So, in addition to the change to switch off sjlj exceptions (which  
causes linkage errors for the absent sjlj routines),
we also need to generate the right name for the eh personality...

OK?
Iain

objc:

	* objc/objc-act.c (objc_eh_personality): Select personality name on  
runtime.
	(objc_init_exceptions): New.
	(objc_begin_try_stmt): Use objc_init_exceptions.
	(objc_build_throw_stmt): Likewise.






^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [Patch ObjC] fix objc.dg/exceptions2.m linkage error.
  2010-12-17 15:52 [Patch ObjC] fix objc.dg/exceptions2.m linkage error IainS
  2010-12-17 19:03 ` Nicola Pero
@ 2010-12-17 21:09 ` Mike Stump
  2010-12-18 11:57   ` IainS
  1 sibling, 1 reply; 6+ messages in thread
From: Mike Stump @ 2010-12-17 21:09 UTC (permalink / raw)
  To: IainS; +Cc: GCC Patches, Mike Stump, Nicola Pero

On Dec 17, 2010, at 6:34 AM, IainS <developer@sandoe-acoustics.co.uk> wrote:
> The NeXT runtime library names its m64 personality routine "___objc_personality_v0"
> 
> So, in addition to the change to switch off sjlj exceptions (which causes linkage errors for the absent sjlj routines),
> we also need to generate the right name for the eh personality...
> 
> OK?

Ok.  If you want to do once per unit, that's fine too.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [Patch ObjC] fix objc.dg/exceptions2.m linkage error.
  2010-12-17 21:09 ` Mike Stump
@ 2010-12-18 11:57   ` IainS
  2010-12-18 14:27     ` Nicola Pero
  0 siblings, 1 reply; 6+ messages in thread
From: IainS @ 2010-12-18 11:57 UTC (permalink / raw)
  To: Nicola Pero; +Cc: GCC Patches, Mike Stump

[-- Attachment #1: Type: text/plain, Size: 1293 bytes --]

Hi Nicola,

On 17 Dec 2010, at 20:53, Mike Stump wrote:

> On Dec 17, 2010, at 6:34 AM, IainS <developer@sandoe- 
> acoustics.co.uk> wrote:
>> The NeXT runtime library names its m64 personality routine  
>> "___objc_personality_v0"
>>
>> So, in addition to the change to switch off sjlj exceptions (which  
>> causes linkage errors for the absent sjlj routines),
>> we also need to generate the right name for the eh personality...
>>
>> OK?
>
> Ok.  If you want to do once per unit, that's fine too.

Hm. I tried the simple approach, with not-very-useful results.

e.g:

   @try {   <<< no error....
     number++;
     @throw o;  <<< error here...
   }


=== (2)

  @throw o;
   @try {
     number++;
     @throw o;  <<< error here...
   }

  when I check the locus on entry to objc_build_throw_stmt () in (2)  
it seems a bit odd.

I've made the desideratum a "TODO" since it looked like we would have  
to stray out of objc-act to fix it.

... although, perhaps, Nicola since you were last amongst this - maybe  
the issue will be obvious to you ;-)

FWIW;

I also corrected the syntax in the dg-error statements for the testcase.

(they would give an error like
   FAIL -fnext-runtime is required to enable Objective-C exception  
syntax - which is very confusing)

cheers
Iain

r168020;

[-- Attachment #2: 168019-objc-except.txt --]
[-- Type: text/plain, Size: 4962 bytes --]

Index: gcc/objc/objc-act.c
===================================================================
--- gcc/objc/objc-act.c	(revision 168019)
+++ gcc/objc/objc-act.c	(working copy)
@@ -5028,11 +5028,42 @@ tree
 objc_eh_personality (void)
 {
   if (!flag_objc_sjlj_exceptions && !objc_eh_personality_decl)
-    objc_eh_personality_decl = build_personality_function ("gnu_objc");
+    objc_eh_personality_decl = build_personality_function 
+				(flag_next_runtime
+						? "objc"
+						: "gnu_objc");
   return objc_eh_personality_decl;
 }
 #endif
 
+static void
+objc_init_exceptions (location_t loc)
+{
+  static bool done = false;
+
+  /* -fobjc-exceptions is required to enable Objective-C exceptions.
+     For example, on Darwin, ObjC exceptions require a sufficiently
+     recent version of the runtime, so the user must ask for them
+     explicitly.  On other platforms, at the moment -fobjc-exceptions
+     triggers -fexceptions which again is required for exceptions to
+     work.
+  */
+  /* TODO: we only really need one error message when the flag is missing.  */
+  if (!flag_objc_exceptions)
+    {
+      error_at (loc, "%<-fobjc-exceptions%> is required to enable Objective-C exception syntax");
+    }
+
+  if (done)
+    return;
+  done = true;
+
+#ifndef OBJCPLUS
+  if (!flag_objc_sjlj_exceptions)
+    using_eh_for_cleanups ();
+#endif
+}
+
 /* Build __builtin_eh_pointer, or the moral equivalent.  In the case
    of Darwin, we'll arrange for it to be initialized (and associated
    with a binding) later.  */
@@ -5334,17 +5365,7 @@ objc_begin_try_stmt (location_t try_locus, tree bo
   c->end_try_locus = input_location;
   cur_try_context = c;
 
-  /* -fobjc-exceptions is required to enable Objective-C exceptions.
-     For example, on Darwin, ObjC exceptions require a sufficiently
-     recent version of the runtime, so the user must ask for them
-     explicitly.  On other platforms, at the moment -fobjc-exceptions
-     triggers -fexceptions which again is required for exceptions to
-     work.
-  */
-  if (!flag_objc_exceptions)
-    {
-      error_at (try_locus, "%<-fobjc-exceptions%> is required to enable Objective-C exception syntax");
-    }
+  objc_init_exceptions (try_locus);
 
   /* Collect the list of local variables.  We'll mark them as volatile
      at the end of compilation of this function to prevent them being
@@ -5552,10 +5573,7 @@ objc_build_throw_stmt (location_t loc, tree throw_
 {
   tree args;
 
-  if (!flag_objc_exceptions)
-    {
-      error_at (loc, "%<-fobjc-exceptions%> is required to enable Objective-C exception syntax");
-    }
+  objc_init_exceptions (loc); 
 
   if (throw_expr == NULL)
     {
Index: gcc/objc/ChangeLog
===================================================================
--- gcc/objc/ChangeLog	(revision 168019)
+++ gcc/objc/ChangeLog	(working copy)
@@ -1,3 +1,11 @@
+2010-12-18  Iain Sandoe  <iains@gcc.gnu.org>
+
+	* objc/objc-act.c (objc_eh_personality): Select personality name on
+	runtime.
+	(objc_init_exceptions): New.
+	(objc_begin_try_stmt): Use objc_init_exceptions.
+	(objc_build_throw_stmt): Likewise.
+
 2010-12-10  Nicola Pero  <nicola.pero@meta-innovation.com>
 
 	* objc-act.c (objc_in_class_extension): New.
Index: gcc/testsuite/ChangeLog
===================================================================
--- gcc/testsuite/ChangeLog	(revision 168019)
+++ gcc/testsuite/ChangeLog	(working copy)
@@ -1,3 +1,7 @@
+2010-12-18  Iain Sandoe  <iains@gcc.gnu.org>
+
+	* fobjc-exceptions.m: Update dg-error syntax.
+
 2010-12-18  Kai Tietz  <kai.tietz@onevision.com>
 
 	PR target/36834
Index: gcc/testsuite/objc.dg/fobjc-exceptions.m
===================================================================
--- gcc/testsuite/objc.dg/fobjc-exceptions.m	(revision 168019)
+++ gcc/testsuite/objc.dg/fobjc-exceptions.m	(working copy)
@@ -5,25 +5,24 @@
 
 int dummy (int number, Object *o)
 {
-  @try {            /* { dg-error "fobjc-exceptions" "is required to enable Objective-C exception syntax" } */
+  @try {            /* { dg-error ".-fobjc-exceptions. is required to enable Objective-C exception syntax" } */
     number++;
-    @throw o;     /* { dg-error "fobjc-exceptions" "is required to enable Objective-C exception syntax" } */
+    @throw o;     /* { dg-error ".-fobjc-exceptions. is required to enable Objective-C exception syntax" } */
   }
   @catch (id object)
     {
       number++;
-      @throw;       /* { dg-error "fobjc-exceptions" "is required to enable Objective-C exception syntax" } */
+      @throw;       /* { dg-error ".-fobjc-exceptions. is required to enable Objective-C exception syntax" } */
     }
   @finally
     {
       number++;
     }
   
-  @synchronized (o) /* { dg-error "fobjc-exceptions" "is required to enable Objective-C exception syntax" } */
+  @synchronized (o) /* { dg-error ".-fobjc-exceptions. is required to enable Objective-C exception syntax" } */
     {
       number++;
     }
   
   return number;
 }
-

[-- Attachment #3: Type: text/plain, Size: 3 bytes --]





^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [Patch ObjC] fix objc.dg/exceptions2.m linkage error.
  2010-12-18 11:57   ` IainS
@ 2010-12-18 14:27     ` Nicola Pero
  2010-12-18 18:58       ` Mike Stump
  0 siblings, 1 reply; 6+ messages in thread
From: Nicola Pero @ 2010-12-18 14:27 UTC (permalink / raw)
  To: IainS; +Cc: GCC Patches, Mike Stump


> I've made the desideratum a "TODO" since it looked like we would have  
> to stray out of objc-act to fix it.

Yes.  Ok, so, in attach, a patch that does it:

 * it changes the compiler to emit the error "-fobjc-exceptions is required to enable Objective-C exception syntax"
only once per compilation unit;

 * it updates the ObjC testcases for this change;

 * it adds corresponding ObjC++ testcases;

 * it also changes the code to always call using_eh_for_cleanups() in objc_init(), if -fobjc-exceptions
(but not -fobjc-sjlj-exceptions) is specified, without waiting for the first ObjC exception syntax (it
makes more sense to me and it's the same way that the C++ frontend does it for C++ exceptions)

Ok to commit ?

Thanks

Index: c-family/c-objc.h
===================================================================
--- c-family/c-objc.h   (revision 168020)
+++ c-family/c-objc.h   (working copy)
@@ -106,6 +106,7 @@ extern bool objc_is_property_ref (tree);
 extern bool objc_string_ref_type_p (tree);
 extern void objc_check_format_arg (tree, tree);
 extern void objc_finish_function (void);
+extern void objc_maybe_warn_exceptions (location_t);
 
 /* The following are provided by the C and C++ front-ends, and called by
    ObjC/ObjC++.  */
Index: c-family/ChangeLog
===================================================================
--- c-family/ChangeLog  (revision 168020)
+++ c-family/ChangeLog  (working copy)
@@ -1,3 +1,8 @@
+2010-12-18  Nicola Pero  <nicola.pero@meta-innovation.com>
+
+       * c-objc.h (objc_maybe_warn_exceptions): New.
+       * stub-objc.c (objc_maybe_warn_exceptions): New.        
+
 2010-12-10  Nathan Froyd  <froydnj@codesourcery.com>
 
        * c-common.h (readonly_error): Declare.
Index: c-family/stub-objc.c
===================================================================
--- c-family/stub-objc.c        (revision 168020)
+++ c-family/stub-objc.c        (working copy)
@@ -455,3 +455,8 @@ void
 objc_finish_function (void)
 {
 }
+
+void
+objc_maybe_warn_exceptions (location_t ARG_UNUSED (loc))
+{
+}
Index: objc/objc-act.c
===================================================================
--- objc/objc-act.c     (revision 168020)
+++ objc/objc-act.c     (working copy)
@@ -626,6 +626,11 @@ objc_init (void)
   if (print_struct_values && !flag_compare_debug)
     generate_struct_by_value_array ();
 
+#ifndef OBJCPLUS
+  if (flag_objc_exceptions && !flag_objc_sjlj_exceptions)
+    using_eh_for_cleanups ();
+#endif
+
   return true;
 }
 
@@ -5036,32 +5041,26 @@ objc_eh_personality (void)
 }
 #endif
 
-static void
-objc_init_exceptions (location_t loc)
+void
+objc_maybe_warn_exceptions (location_t loc)
 {
-  static bool done = false;
-
   /* -fobjc-exceptions is required to enable Objective-C exceptions.
      For example, on Darwin, ObjC exceptions require a sufficiently
      recent version of the runtime, so the user must ask for them
      explicitly.  On other platforms, at the moment -fobjc-exceptions
      triggers -fexceptions which again is required for exceptions to
-     work.
-  */
-  /* TODO: we only really need one error message when the flag is missing.  */
+     work.  */
   if (!flag_objc_exceptions)
     {
-      error_at (loc, "%<-fobjc-exceptions%> is required to enable Objective-C exception syntax");
-    }
+      /* Warn only once per compilation unit.  */
+      static bool warned = false;
 
-  if (done)
-    return;
-  done = true;
-
-#ifndef OBJCPLUS
-  if (!flag_objc_sjlj_exceptions)
-    using_eh_for_cleanups ();
-#endif
+      if (!warned)
+       {
+         error_at (loc, "%<-fobjc-exceptions%> is required to enable Objective-C exception syntax");
+         warned = true;
+       }
+    }
 }
 
 /* Build __builtin_eh_pointer, or the moral equivalent.  In the case
@@ -5365,8 +5364,6 @@ objc_begin_try_stmt (location_t try_locus, tree bo
   c->end_try_locus = input_location;
   cur_try_context = c;
 
-  objc_init_exceptions (try_locus);
-
   /* 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.  */
@@ -5573,7 +5570,7 @@ objc_build_throw_stmt (location_t loc, tree throw_
 {
   tree args;
 
-  objc_init_exceptions (loc); 
+  objc_maybe_warn_exceptions (loc);
 
   if (throw_expr == NULL)
     {
Index: objc/ChangeLog
===================================================================
--- objc/ChangeLog      (revision 168020)
+++ objc/ChangeLog      (working copy)
@@ -1,3 +1,12 @@
+2010-12-18  Nicola Pero  <nicola.pero@meta-innovation.com>
+
+       * objc-act.c (objc_init): Call using_eh_for_cleanups.
+       (objc_init_exceptions): Renamed to objc_maybe_warn_exceptions.  Do
+       not call using_eh_for_cleanups.
+       (objc_begin_try_stmt): Do not call objc_init_exceptions.
+       (objc_build_throw_stmt): Updated call to
+       objc_maybe_warn_exceptions.
+
 2010-12-18  Iain Sandoe  <iains@gcc.gnu.org>
 
        * objc/objc-act.c (objc_eh_personality): Select personality name on
Index: ChangeLog
===================================================================
--- ChangeLog   (revision 168020)
+++ ChangeLog   (working copy)
@@ -1,3 +1,10 @@
+2010-12-18  Nicola Pero  <nicola.pero@meta-innovation.com>
+
+       * c-parser.c (c_parser_objc_try_catch_finally_statement): Call
+       objc_maybe_warn_exceptions.
+       (c_parser_objc_synchronized_statement): Call
+       objc_maybe_warn_exceptions.
+       
 2010-12-18  Kai Tietz  <kai.tietz@onevision.com>
 
        PR target/36834
Index: testsuite/ChangeLog
===================================================================
--- testsuite/ChangeLog (revision 168020)
+++ testsuite/ChangeLog (working copy)
@@ -1,6 +1,15 @@
+2010-12-18  Nicola Pero  <nicola.pero@meta-innovation.com>
+
+       * objc.dg/fobjc-exceptions-1.m: Updated.
+       * objc.dg/fobjc-exceptions-2.m: New.
+       * objc.dg/fobjc-exceptions-3.m: New.
+       * obj-c++.dg/fobjc-exceptions-1.mm: New.
+       * obj-c++.dg/fobjc-exceptions-2.mm: New.
+       * obj-c++.dg/fobjc-exceptions-3.mm: New.
+       
 2010-12-18  Iain Sandoe  <iains@gcc.gnu.org>
 
-       * fobjc-exceptions.m: Update dg-error syntax.
+       * objc.dg/fobjc-exceptions.m: Update dg-error syntax.
 
 2010-12-18  Kai Tietz  <kai.tietz@onevision.com>
 
Index: testsuite/objc.dg/fobjc-exceptions-2.m
===================================================================
--- testsuite/objc.dg/fobjc-exceptions-2.m      (revision 0)
+++ testsuite/objc.dg/fobjc-exceptions-2.m      (revision 0)
@@ -0,0 +1,29 @@
+/* Test that Objective-C exceptions cause an error with -fobjc-exceptions.  */
+/* { dg-do compile } */
+
+@class Object;
+
+int dummy (int number, Object *o)
+{
+  @synchronized (o) /* { dg-error ".-fobjc-exceptions. is required to enable Objective-C exception syntax" } */
+    {
+      number++;
+    }
+
+  @try {            /* Nothing, error has already been produced.  */
+    number++;
+    @throw o;       /* Nothing, error has already been produced.  */
+  }
+  @catch (id object)
+    {
+      number++;
+      @throw;       /* Nothing, error has already been produced.  */
+    }
+  @finally
+    {
+      number++;
+    }
+  
+  
+  return number;
+}
Index: testsuite/objc.dg/fobjc-exceptions-3.m
===================================================================
--- testsuite/objc.dg/fobjc-exceptions-3.m      (revision 0)
+++ testsuite/objc.dg/fobjc-exceptions-3.m      (revision 0)
@@ -0,0 +1,30 @@
+/* Test that Objective-C exceptions cause an error with -fobjc-exceptions.  */
+/* { dg-do compile } */
+
+@class Object;
+
+int dummy (int number, Object *o)
+{
+  @throw o;           /* { dg-error ".-fobjc-exceptions. is required to enable Objective-C exception syntax" } */
+
+  @try {              /* Nothing, error has already been produced.  */
+    number++;
+    @throw o;         /* Nothing, error has already been produced.  */
+  }
+  @catch (id object)
+    {
+      number++;
+      @throw;        /* Nothing, error has already been produced.  */
+    }
+  @finally
+    {
+      number++;
+    }
+  
+  @synchronized (o)   /* Nothing, error has already been produced.  */
+    {
+      number++;
+    }
+  
+  return number;
+}
Index: testsuite/objc.dg/fobjc-exceptions.m
===================================================================
--- testsuite/objc.dg/fobjc-exceptions.m        (revision 168020)
+++ testsuite/objc.dg/fobjc-exceptions.m        (working copy)
@@ -1,28 +0,0 @@
-/* Test that Objective-C exceptions cause an error with -fobjc-exceptions.  */
-/* { dg-do compile } */
-
-@class Object;
-
-int dummy (int number, Object *o)
-{
-  @try {            /* { dg-error ".-fobjc-exceptions. is required to enable Objective-C exception syntax" } */
-    number++;
-    @throw o;     /* { dg-error ".-fobjc-exceptions. is required to enable Objective-C exception syntax" } */
-  }
-  @catch (id object)
-    {
-      number++;
-      @throw;       /* { dg-error ".-fobjc-exceptions. is required to enable Objective-C exception syntax" } */
-    }
-  @finally
-    {
-      number++;
-    }
-  
-  @synchronized (o) /* { dg-error ".-fobjc-exceptions. is required to enable Objective-C exception syntax" } */
-    {
-      number++;
-    }
-  
-  return number;
-}
Index: testsuite/objc.dg/fobjc-exceptions-1.m
===================================================================
--- testsuite/objc.dg/fobjc-exceptions-1.m      (revision 168020)
+++ testsuite/objc.dg/fobjc-exceptions-1.m      (working copy)
@@ -7,19 +7,19 @@ int dummy (int number, Object *o)
 {
   @try {            /* { dg-error ".-fobjc-exceptions. is required to enable Objective-C exception syntax" } */
     number++;
-    @throw o;     /* { dg-error ".-fobjc-exceptions. is required to enable Objective-C exception syntax" } */
+    @throw o;       /* Nothing, error has already been produced.  */
   }
   @catch (id object)
     {
       number++;
-      @throw;       /* { dg-error ".-fobjc-exceptions. is required to enable Objective-C exception syntax" } */
+      @throw;       /* Nothing, error has already been produced.  */
     }
   @finally
     {
       number++;
     }
   
-  @synchronized (o) /* { dg-error ".-fobjc-exceptions. is required to enable Objective-C exception syntax" } */
+  @synchronized (o) /* Nothing, error has already been produced.  */
     {
       number++;
     }
Index: testsuite/obj-c++.dg/fobjc-exceptions-2.mm
===================================================================
--- testsuite/obj-c++.dg/fobjc-exceptions-2.mm  (revision 0)
+++ testsuite/obj-c++.dg/fobjc-exceptions-2.mm  (revision 0)
@@ -0,0 +1,29 @@
+/* Test that Objective-C exceptions cause an error with -fobjc-exceptions.  */
+/* { dg-do compile } */
+
+@class Object;
+
+int dummy (int number, Object *o)
+{
+  @synchronized (o) /* { dg-error ".-fobjc-exceptions. is required to enable Objective-C exception syntax" } */
+    {
+      number++;
+    }
+
+  @try {            /* Nothing, error has already been produced.  */
+    number++;
+    @throw o;       /* Nothing, error has already been produced.  */
+  }
+  @catch (id object)
+    {
+      number++;
+      @throw;       /* Nothing, error has already been produced.  */
+    }
+  @finally
+    {
+      number++;
+    }
+  
+  
+  return number;
+}
Index: testsuite/obj-c++.dg/fobjc-exceptions-3.mm
===================================================================
--- testsuite/obj-c++.dg/fobjc-exceptions-3.mm  (revision 0)
+++ testsuite/obj-c++.dg/fobjc-exceptions-3.mm  (revision 0)
@@ -0,0 +1,30 @@
+/* Test that Objective-C exceptions cause an error with -fobjc-exceptions.  */
+/* { dg-do compile } */
+
+@class Object;
+
+int dummy (int number, Object *o)
+{
+  @throw o;           /* { dg-error ".-fobjc-exceptions. is required to enable Objective-C exception syntax" } */
+
+  @try {              /* Nothing, error has already been produced.  */
+    number++;
+    @throw o;         /* Nothing, error has already been produced.  */
+  }
+  @catch (id object)
+    {
+      number++;
+      @throw;        /* Nothing, error has already been produced.  */
+    }
+  @finally
+    {
+      number++;
+    }
+  
+  @synchronized (o)   /* Nothing, error has already been produced.  */
+    {
+      number++;
+    }
+  
+  return number;
+}
Index: testsuite/obj-c++.dg/fobjc-exceptions-1.mm
===================================================================
--- testsuite/obj-c++.dg/fobjc-exceptions-1.mm  (revision 0)
+++ testsuite/obj-c++.dg/fobjc-exceptions-1.mm  (revision 0)
@@ -0,0 +1,28 @@
+/* Test that Objective-C exceptions cause an error with -fobjc-exceptions.  */
+/* { dg-do compile } */
+
+@class Object;
+
+int dummy (int number, Object *o)
+{
+  @try {            /* { dg-error ".-fobjc-exceptions. is required to enable Objective-C exception syntax" } */
+    number++;
+    @throw o;       /* Nothing, error has already been produced.  */
+  }
+  @catch (id object)
+    {
+      number++;
+      @throw;       /* Nothing, error has already been produced.  */
+    }
+  @finally
+    {
+      number++;
+    }
+  
+  @synchronized (o) /* Nothing, error has already been produced.  */
+    {
+      number++;
+    }
+  
+  return number;
+}
Index: cp/ChangeLog
===================================================================
--- cp/ChangeLog        (revision 168020)
+++ cp/ChangeLog        (working copy)
@@ -1,3 +1,9 @@
+2010-12-18  Nicola Pero  <nicola.pero@meta-innovation.com>
+
+       * parser.c (cp_parser_objc_try_catch_finally_statement): Call
+       objc_maybe_warn_exceptions.
+       (cp_parser_objc_synchronized_statement): Same change.
+       
 2010-12-17  Jason Merrill  <jason@redhat.com>
 
        PR c++/46670
Index: cp/parser.c
===================================================================
--- cp/parser.c (revision 168020)
+++ cp/parser.c (working copy)
@@ -22692,6 +22692,7 @@ cp_parser_objc_try_catch_finally_statement (cp_par
 
   cp_parser_require_keyword (parser, RID_AT_TRY, RT_AT_TRY);
   location = cp_lexer_peek_token (parser->lexer)->location;
+  objc_maybe_warn_exceptions (location);
   /* NB: The @try block needs to be wrapped in its own STATEMENT_LIST
      node, lest it get absorbed into the surrounding block.  */
   stmt = push_stmt_list ();
@@ -22784,6 +22785,7 @@ cp_parser_objc_synchronized_statement (cp_parser *
   cp_parser_require_keyword (parser, RID_AT_SYNCHRONIZED, RT_AT_SYNCHRONIZED);
 
   location = cp_lexer_peek_token (parser->lexer)->location;
+  objc_maybe_warn_exceptions (location);
   cp_parser_require (parser, CPP_OPEN_PAREN, RT_OPEN_PAREN);
   lock = cp_parser_expression (parser, false, NULL);
   cp_parser_require (parser, CPP_CLOSE_PAREN, RT_CLOSE_PAREN);
Index: c-parser.c
===================================================================
--- c-parser.c  (revision 168020)
+++ c-parser.c  (working copy)
@@ -7547,6 +7547,7 @@ c_parser_objc_try_catch_finally_statement (c_parse
   gcc_assert (c_parser_next_token_is_keyword (parser, RID_AT_TRY));
   c_parser_consume_token (parser);
   location = c_parser_peek_token (parser)->location;
+  objc_maybe_warn_exceptions (location);
   stmt = c_parser_compound_statement (parser);
   objc_begin_try_stmt (location, stmt);
 
@@ -7628,6 +7629,7 @@ c_parser_objc_synchronized_statement (c_parser *pa
   gcc_assert (c_parser_next_token_is_keyword (parser, RID_AT_SYNCHRONIZED));
   c_parser_consume_token (parser);
   loc = c_parser_peek_token (parser)->location;
+  objc_maybe_warn_exceptions (loc);
   if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
     {
       expr = c_parser_expression (parser).value;


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [Patch ObjC] fix objc.dg/exceptions2.m linkage error.
  2010-12-18 14:27     ` Nicola Pero
@ 2010-12-18 18:58       ` Mike Stump
  0 siblings, 0 replies; 6+ messages in thread
From: Mike Stump @ 2010-12-18 18:58 UTC (permalink / raw)
  To: Nicola Pero; +Cc: IainS, GCC Patches

On Dec 18, 2010, at 5:34 AM, Nicola Pero wrote:
> * it changes the compiler to emit the error "-fobjc-exceptions is required to enable Objective-C exception syntax"
> only once per compilation unit;
> 
> * it updates the ObjC testcases for this change;
> 
> * it adds corresponding ObjC++ testcases;
> 
> * it also changes the code to always call using_eh_for_cleanups() in objc_init(), if -fobjc-exceptions
> (but not -fobjc-sjlj-exceptions) is specified, without waiting for the first ObjC exception syntax (it
> makes more sense to me and it's the same way that the C++ frontend does it for C++ exceptions)
> 
> Ok to commit ?

Ok.  Please watch for regressions or build failures this time of year, given where we are in the release cycle.

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2010-12-18 17:31 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-12-17 15:52 [Patch ObjC] fix objc.dg/exceptions2.m linkage error IainS
2010-12-17 19:03 ` Nicola Pero
2010-12-17 21:09 ` Mike Stump
2010-12-18 11:57   ` IainS
2010-12-18 14:27     ` Nicola Pero
2010-12-18 18:58       ` Mike Stump

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).