From patchwork Mon Nov 29 18:41:31 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicola Pero X-Patchwork-Id: 73476 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 8374EB70AA for ; Tue, 30 Nov 2010 05:41:50 +1100 (EST) Received: (qmail 13343 invoked by alias); 29 Nov 2010 18:41:48 -0000 Received: (qmail 13329 invoked by uid 22791); 29 Nov 2010 18:41:46 -0000 X-SWARE-Spam-Status: No, hits=-1.4 required=5.0 tests=AWL, BAYES_00, 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; Mon, 29 Nov 2010 18:41:42 +0000 Received: from eggs.gnu.org ([140.186.70.92]:37822) by fencepost.gnu.org with esmtps (TLS-1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.69) (envelope-from ) id 1PN8fN-0003DE-8J for gcc-patches@gnu.org; Mon, 29 Nov 2010 13:41:33 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1PN8fM-0006MI-GB for gcc-patches@gnu.org; Mon, 29 Nov 2010 13:41:35 -0500 Received: from smtp121.iad.emailsrvr.com ([207.97.245.121]:49364) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1PN8fM-0006Lv-8q for gcc-patches@gnu.org; Mon, 29 Nov 2010 13:41:32 -0500 Received: from localhost (localhost.localdomain [127.0.0.1]) by smtp42.relay.iad1a.emailsrvr.com (SMTP Server) with ESMTP id 3FBE714850B for ; Mon, 29 Nov 2010 13:41:31 -0500 (EST) Received: from dynamic8.wm-web.iad.mlsrvr.com (dynamic8.wm-web.iad1a.rsapps.net [192.168.2.149]) by smtp42.relay.iad1a.emailsrvr.com (SMTP Server) with ESMTP id 2EC97148361 for ; Mon, 29 Nov 2010 13:41:31 -0500 (EST) Received: from meta-innovation.com (localhost [127.0.0.1]) by dynamic8.wm-web.iad.mlsrvr.com (Postfix) with ESMTP id 1F114305006C for ; Mon, 29 Nov 2010 13:41:31 -0500 (EST) Received: by www2.webmail.us (Authenticated sender: nicola.pero@meta-innovation.com, from: nicola.pero@meta-innovation.com) with HTTP; Mon, 29 Nov 2010 19:41:31 +0100 (CET) Date: Mon, 29 Nov 2010 19:41:31 +0100 (CET) Subject: ObjC/ObjC++: fix ICE on duplicate @implementation of the same class From: "Nicola Pero" To: "gcc-patches@gnu.org" MIME-Version: 1.0 X-Type: plain Message-ID: <1291056091.12541206@192.168.2.228> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 3) 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 the ObjC/ObjC++ ICE when there is a duplicate @implementation of the same Objective-C class. Testcases included. Ok to commit ? Thanks Index: objc/objc-act.c =================================================================== --- objc/objc-act.c (revision 167242) +++ objc/objc-act.c (working copy) @@ -9540,10 +9540,13 @@ start_class (enum tree_code code, tree class_name, { error ("reimplementation of class %qE", class_name); - return error_mark_node; + /* TODO: error message saying where it was previously + implemented. */ + break; } - implemented_classes = tree_cons (NULL_TREE, class_name, - implemented_classes); + if (chain == NULL_TREE) + implemented_classes = tree_cons (NULL_TREE, class_name, + implemented_classes); } /* Reset for multiple classes per file. */ Index: objc/ChangeLog =================================================================== --- objc/ChangeLog (revision 167242) +++ objc/ChangeLog (working copy) @@ -1,5 +1,11 @@ 2010-11-29 Nicola Pero + * objc-act.c (start_class): When a class is reimplemented, + generate an error and avoid adding the class to the list of + implemented classes again, but do not return error_mark_node. + +2010-11-29 Nicola Pero + * objc-act.c (objc_eh_runtime_type): Avoid ICE if error_mark_node is passed as argument. (objc_begin_catch_clause): Added code to deal with an Index: testsuite/ChangeLog =================================================================== --- testsuite/ChangeLog (revision 167242) +++ testsuite/ChangeLog (working copy) @@ -1,3 +1,8 @@ +2010-11-29 Nicola Pero + + * objc.dg/duplicate-class-1.m: New. + * obj-c++.dg/duplicate-class-1.mm: New. + 2010-11-29 Iain Sandoe Mike Stump Index: testsuite/objc.dg/duplicate-class-1.m =================================================================== --- testsuite/objc.dg/duplicate-class-1.m (revision 0) +++ testsuite/objc.dg/duplicate-class-1.m (revision 0) @@ -0,0 +1,31 @@ +/* Contributed by Nicola Pero , November 2010. */ +/* { dg-do compile } */ + +/* Test that a duplicated @implementation for the same class does not + crash the compiler. */ + +@interface Test +{ + Class isa; +} +- (int) test; +@end + +@implementation Test +- (int) test +{ + return 4; +} +@end + +/* The most likely cause is that the programmer meant this to be a + category, so check what happens if we have some different methods + in there. */ +@implementation Test +- (int) test2 /* { dg-error "reimplementation of class .Test." } */ +{ + return [self test]; +} +@end +/* { dg-warning "incomplete implementation" "" { target *-*-* } 29 } */ +/* { dg-warning "not found" "" { target *-*-* } 29 } */ Index: testsuite/obj-c++.dg/duplicate-class-1.mm =================================================================== --- testsuite/obj-c++.dg/duplicate-class-1.mm (revision 0) +++ testsuite/obj-c++.dg/duplicate-class-1.mm (revision 0) @@ -0,0 +1,31 @@ +/* Contributed by Nicola Pero , November 2010. */ +/* { dg-do compile } */ + +/* Test that a duplicated @implementation for the same class does not + crash the compiler. */ + +@interface Test +{ + Class isa; +} +- (int) test; +@end + +@implementation Test +- (int) test +{ + return 4; +} +@end + +/* The most likely cause is that the programmer meant this to be a + category, so check what happens if we have some different methods + in there. */ +@implementation Test /* { dg-error "reimplementation of class .Test." } */ +- (int) test2 +{ + return [self test]; +} +@end +/* { dg-warning "incomplete implementation" "" { target *-*-* } 29 } */ +/* { dg-warning "not found" "" { target *-*-* } 29 } */