From patchwork Sat Dec 18 13:34:03 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicola Pero X-Patchwork-Id: 76072 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) by ozlabs.org (Postfix) with SMTP id 6B438B7063 for ; Sun, 19 Dec 2010 00:34:16 +1100 (EST) Received: (qmail 2186 invoked by alias); 18 Dec 2010 13:34:14 -0000 Received: (qmail 1067 invoked by uid 22791); 18 Dec 2010 13:34:12 -0000 X-SWARE-Spam-Status: No, hits=-0.3 required=5.0 tests=AWL, BAYES_50, RCVD_IN_DNSWL_LOW, TW_BJ, TW_JL, TW_TM, T_FILL_THIS_FORM_SHORT X-Spam-Check-By: sourceware.org Received: from smtp131.iad.emailsrvr.com (HELO smtp131.iad.emailsrvr.com) (207.97.245.131) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Sat, 18 Dec 2010 13:34:05 +0000 Received: from localhost (localhost.localdomain [127.0.0.1]) by smtp43.relay.iad1a.emailsrvr.com (SMTP Server) with ESMTP id D02D42D02F9; Sat, 18 Dec 2010 08:34:03 -0500 (EST) Received: from dynamic4.wm-web.iad.mlsrvr.com (dynamic4.wm-web.iad1a.rsapps.net [192.168.2.153]) by smtp43.relay.iad1a.emailsrvr.com (SMTP Server) with ESMTP id 8C92D2D021C; Sat, 18 Dec 2010 08:34:03 -0500 (EST) Received: from meta-innovation.com (localhost [127.0.0.1]) by dynamic4.wm-web.iad.mlsrvr.com (Postfix) with ESMTP id 7D2BB1D4A2AE; Sat, 18 Dec 2010 08:34:03 -0500 (EST) Received: by www2.webmail.us (Authenticated sender: nicola.pero@meta-innovation.com, from: nicola.pero@meta-innovation.com) with HTTP; Sat, 18 Dec 2010 14:34:03 +0100 (CET) Date: Sat, 18 Dec 2010 14:34:03 +0100 (CET) Subject: Re: [Patch ObjC] fix objc.dg/exceptions2.m linkage error. From: "Nicola Pero" To: "IainS" Cc: "GCC Patches" , "Mike Stump" MIME-Version: 1.0 X-Type: plain In-Reply-To: <0772A5AF-C08B-43B6-B3A9-2B1864CC208E@sandoe-acoustics.co.uk> References: <0772A5AF-C08B-43B6-B3A9-2B1864CC208E@sandoe-acoustics.co.uk> Message-ID: <1292679243.51125513@192.168.2.228> X-IsSubscribed: yes Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org > 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 + + * c-objc.h (objc_maybe_warn_exceptions): New. + * stub-objc.c (objc_maybe_warn_exceptions): New. + 2010-12-10 Nathan Froyd * 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 + + * 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 * 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 + + * 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 PR target/36834 Index: testsuite/ChangeLog =================================================================== --- testsuite/ChangeLog (revision 168020) +++ testsuite/ChangeLog (working copy) @@ -1,6 +1,15 @@ +2010-12-18 Nicola Pero + + * 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 - * fobjc-exceptions.m: Update dg-error syntax. + * objc.dg/fobjc-exceptions.m: Update dg-error syntax. 2010-12-18 Kai Tietz 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 + + * 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 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;