From patchwork Tue Feb 22 23:22:52 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicola Pero X-Patchwork-Id: 84016 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 23DB7B70DB for ; Wed, 23 Feb 2011 10:23:05 +1100 (EST) Received: (qmail 9920 invoked by alias); 22 Feb 2011 23:23:03 -0000 Received: (qmail 9912 invoked by uid 22791); 22 Feb 2011 23:23:02 -0000 X-SWARE-Spam-Status: No, hits=-1.3 required=5.0 tests=AWL, BAYES_00, SARE_SUB_ENC_UTF8, TW_BJ, T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from fencepost.gnu.org (HELO fencepost.gnu.org) (140.186.70.10) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Tue, 22 Feb 2011 23:22:57 +0000 Received: from eggs.gnu.org ([140.186.70.92]:47079) by fencepost.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1Ps1ZH-0001W9-BN for gcc-patches@gnu.org; Tue, 22 Feb 2011 18:22:55 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Ps1ZG-0007aB-0E for gcc-patches@gnu.org; Tue, 22 Feb 2011 18:22:55 -0500 Received: from smtp201.iad.emailsrvr.com ([207.97.245.201]:52066) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Ps1ZF-0007a1-U8 for gcc-patches@gnu.org; Tue, 22 Feb 2011 18:22:53 -0500 Received: from localhost (localhost.localdomain [127.0.0.1]) by smtp50.relay.iad1a.emailsrvr.com (SMTP Server) with ESMTP id A99E4370E8B for ; Tue, 22 Feb 2011 18:22:52 -0500 (EST) Received: from dynamic8.wm-web.iad.mlsrvr.com (dynamic8.wm-web.iad1a.rsapps.net [192.168.2.149]) by smtp50.relay.iad1a.emailsrvr.com (SMTP Server) with ESMTP id 9544D370E4D for ; Tue, 22 Feb 2011 18:22:52 -0500 (EST) Received: from meta-innovation.com (localhost [127.0.0.1]) by dynamic8.wm-web.iad.mlsrvr.com (Postfix) with ESMTP id 72964305006C for ; Tue, 22 Feb 2011 18:22:52 -0500 (EST) Received: by www2.webmail.us (Authenticated sender: nicola.pero@meta-innovation.com, from: nicola.pero@meta-innovation.com) with HTTP; Wed, 23 Feb 2011 00:22:52 +0100 (CET) Date: Wed, 23 Feb 2011 00:22:52 +0100 (CET) Subject: =?UTF-8?Q?ObjC=20patch:=20fix=20CLASS=5FHAS=5FEXCEPTION=5FATTR?= From: "Nicola Pero" To: "gcc-patches@gnu.org" MIME-Version: 1.0 X-Type: plain Message-ID: <1298416972.467722810@192.168.4.58> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 3) X-Received-From: 207.97.245.201 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 This patch fixes one of the pending FIXMEs with the big ObjC patch committed a few days ago, which is #define CLASS_HAS_EXCEPTION_ATTR(CLASS) ((CLASS)->type.lang_flag_0) The problem there is that that flag is already in use by C and C++ and there is potential for conflict if it is used for arbitrary tree nodes (as it is by the new code). But we don't need to use it on arbitrary tree nodes. To implement what is needed, we only need to use it for CLASS_INTERFACE_TYPE nodes, which are Objective-C-specific frontend nodes, and no conflict can arise. :-) This patch removes copying the CLASS_HAS_EXCEPTION_ATTR() flag from the CLASS_INTERFACE_TYPE node to the corresponding struct when creating the struct, as there is no need to have that flag there - it's never used. This removes any possibility of conflict. I think that copying of the flag into the struct was inspired by the copying of the deprecated flag into the struct, but in this case there is no reason to copy the flag. I also added a basic testcase for "attribute((objc_exception))". It only checks that the attribute is accepted correctly; it would be good to have a testcase checking metadata generation for Apple 64-bit (I did check that the flag gets detected correctly during metadata generation by just hacking some code into the compiler; it would be nice to have a complete standard test for the Apple 64-bit that checks the actual output). Ok to commit ? Thanks PS: The other missing changes Index: objc/ChangeLog =================================================================== --- objc/ChangeLog (revision 170412) +++ objc/ChangeLog (working copy) @@ -1,5 +1,12 @@ 2011-02-22 Nicola Pero + * objc-act.c (build_private_template): Do not copy the + CLASS_HAS_EXCEPTION_ATTR from the class to the struct. + * objc-act.h (CLASS_HAS_EXCEPTION_ATTR): Define using + TYPE_LANG_SLOT_0. + +2011-02-22 Nicola Pero + PR objc/47832 * objc-act.c (flexible_array_type_p): New. (add_instance_variable): Produce an error if an instance variable Index: objc/objc-act.c =================================================================== --- objc/objc-act.c (revision 170412) +++ objc/objc-act.c (working copy) @@ -4203,9 +4203,6 @@ build_private_template (tree klass) /* Copy the attributes from the class to the type. */ if (TREE_DEPRECATED (klass)) TREE_DEPRECATED (record) = 1; - - if (CLASS_HAS_EXCEPTION_ATTR (klass)) - CLASS_HAS_EXCEPTION_ATTR (record) = 1; } } Index: objc/objc-act.h =================================================================== --- objc/objc-act.h (revision 170411) +++ objc/objc-act.h (working copy) @@ -164,10 +164,8 @@ typedef enum objc_property_assign_semantics { #define CLASS_CATEGORY_LIST(CLASS) TREE_VEC_ELT (TYPE_LANG_SLOT_1 (CLASS), 3) #define CLASS_PROTOCOL_LIST(CLASS) TREE_VEC_ELT (TYPE_LANG_SLOT_1 (CLASS), 4) #define TOTAL_CLASS_RAW_IVARS(CLASS) TREE_VEC_ELT (TYPE_LANG_SLOT_1 (CLASS), 5) +#define CLASS_HAS_EXCEPTION_ATTR(CLASS) (TYPE_LANG_FLAG_0 (CLASS)) -/* FIXME */ -#define CLASS_HAS_EXCEPTION_ATTR(CLASS) ((CLASS)->type.lang_flag_0) - #define PROTOCOL_NAME(CLASS) ((CLASS)->type.name) #define PROTOCOL_LIST(CLASS) TREE_VEC_ELT (TYPE_LANG_SLOT_1 (CLASS), 0) #define PROTOCOL_NST_METHODS(CLASS) ((CLASS)->type.minval) Index: testsuite/ChangeLog =================================================================== --- testsuite/ChangeLog (revision 170412) +++ testsuite/ChangeLog (working copy) @@ -1,5 +1,9 @@ 2011-02-22 Nicola Pero + * objc.dg/attributes/objc-exception-1.m: New. + +2011-02-22 Nicola Pero + PR objc/47832 * objc.dg/type-size-3.m: Updated error message. * objc.dg/type-size-4.m: New test. Index: testsuite/objc.dg/attributes/objc-exception-1.m =================================================================== --- testsuite/objc.dg/attributes/objc-exception-1.m (revision 0) +++ testsuite/objc.dg/attributes/objc-exception-1.m (revision 0) @@ -0,0 +1,32 @@ +/* Contributed by Nicola Pero , February 2011. */ +/* { dg-do compile } */ + +/* Test that the 'objc_exception' attribute is accepted for + @interfaces, but not for anything else. */ + +#include + +/* Fine. */ +__attribute__ ((objc_exception)) +@interface MyClass +{ + Class isa; +} +@end + +/* Fine. */ +__attribute__ ((__objc_exception__)) +@interface MyClass2 +{ + Class isa; +} +@end + +__attribute__ ((objc_exception)) +@protocol MyProtocol; /* { dg-warning "ignored" } */ + +__attribute__ ((objc_exception)) +int myVariable; /* { dg-warning "ignored" } */ + +__attribute__ ((objc_exception)) +int myFunction (int argument); /* { dg-warning "ignored" } */