From patchwork Wed Sep 4 13:34:19 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Senthil Kumar Selvaraj X-Patchwork-Id: 272622 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]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client CN "www.sourceware.org", Issuer "StartCom Class 1 Primary Intermediate Server CA" (not verified)) by ozlabs.org (Postfix) with ESMTPS id 65A7F2C0089 for ; Wed, 4 Sep 2013 23:40:27 +1000 (EST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:cc:subject:message-id:references:mime-version :content-type:in-reply-to; q=dns; s=default; b=r0iR+HdU97thjK9Gk V8DiR/dF2oOnwXRyRsGFdfNJbFbSJj19LacV/55kGqN+u15I9P+TEpK5SdcktFGw NnqKuSgRpM1xB1qP80Qi9NIBDp+659E8e5qlBwz7bISFM7MSesvFyHqKYMIluGHQ tX1X3zlDb/UJOUgqx8xuS7Q8gs= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:cc:subject:message-id:references:mime-version :content-type:in-reply-to; s=default; bh=MbDscTdyaRo7S3s4WcD6DGS oW4w=; b=eJUj6NsiTgoBMq8JufEasIllfj2spP05v9Ua2cUKxKRIZgiFEgJbzC2 hluJ2olwB3zDqA7hlv5RQGoPiS0ZzSyvF8UXhfybmX58LC/cOFdkoSnH8kmgpnf9 GjzUbiByJUEr4ACI4wSfkN7YMNpC5WIMLbGo15FdPPzXz0GfZsE0= Received: (qmail 31207 invoked by alias); 4 Sep 2013 13:40:20 -0000 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 Received: (qmail 31188 invoked by uid 89); 4 Sep 2013 13:40:20 -0000 Received: from nasmtp02.atmel.com (HELO nasmtp02.atmel.com) (204.2.163.16) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-SHA encrypted) ESMTPS; Wed, 04 Sep 2013 13:40:20 +0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-4.5 required=5.0 tests=AWL, BAYES_00, RP_MATCHES_RCVD, SPF_SOFTFAIL autolearn=ham version=3.3.2 X-HELO: nasmtp02.atmel.com Received: from apsmtp01.atmel.com (10.168.254.31) by sjoedg01.corp.atmel.com (10.64.253.30) with Microsoft SMTP Server (TLS) id 14.2.342.3; Wed, 4 Sep 2013 06:47:38 -0700 Received: from PENCHT01.corp.atmel.com (10.168.5.161) by apsmtp01.atmel.com (10.168.254.31) with Microsoft SMTP Server (TLS) id 14.2.342.3; Wed, 4 Sep 2013 21:37:59 +0800 Received: from atmel.com (10.168.5.13) by cas-ap.atmel.com (10.168.5.161) with Microsoft SMTP Server (TLS) id 14.2.342.3; Wed, 4 Sep 2013 21:34:17 +0800 Date: Wed, 4 Sep 2013 19:04:19 +0530 From: Senthil Kumar Selvaraj To: "Joseph S. Myers" CC: "gcc-patches@gcc.gnu.org" , "joern.rennecke@embecosm.com" Subject: Re: [Patch] Fix infinite loop/crash if array initializer index equals max value Message-ID: <20130904133418.GA726@atmel.com> References: <32F9C30D650DFD43AADDA3FCB17101806AC7E8FA@penmbx02> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.21 (2010-09-15) X-IsSubscribed: yes On Fri, Aug 23, 2013 at 09:49:55PM +0000, Joseph S. Myers wrote: > On Thu, 22 Aug 2013, Selvaraj, Senthil_Kumar wrote: > > > 2013-08-23 Senthil Kumar Selvaraj > > * c-typeck.c (output_pending_init_elements): Handle overflow of > > constructor_unfilled_index. > > This patch needs to add include a testcase to the testsuite that fails > before and passes after the patch. (I realise such a test may only be > able to run for a subset of targets.) Reattaching the patch with a testcase for the AVR target. I'm not sure how to generalize the testcase for other targets - the constant is the max value (unsigned) of the mode used to represent initialized array indices. The attached test fails with a timeout before applying the patch, and passes after applying it. Regards Senthil gcc/c/ChangeLog 2013-09-04 Senthil Kumar Selvaraj * c-typeck.c (output_pending_init_elements): Handle overflow of constructor_unfilled_index. gcc/testsuite/ChangeLog 2013-09-04 Senthil Kumar Selvaraj * gcc.dg/large-size-array-7.c: New test to verify overflow handling of constructor_unfilled_index. diff --git gcc/c/c-typeck.c gcc/c/c-typeck.c index 30871db..ed2e37a 100644 --- gcc/c/c-typeck.c +++ gcc/c/c-typeck.c @@ -7953,8 +7953,9 @@ output_pending_init_elements (int all, struct obstack * braced_init_obstack) TREE_TYPE (constructor_type), constructor_unfilled_index, 0, false, braced_init_obstack); - else if (tree_int_cst_lt (constructor_unfilled_index, - elt->purpose)) + else if (!TREE_OVERFLOW_P (constructor_unfilled_index) + && tree_int_cst_lt (constructor_unfilled_index, + elt->purpose)) { /* Advance to the next smaller node. */ if (elt->left) @@ -7979,7 +7980,8 @@ output_pending_init_elements (int all, struct obstack * braced_init_obstack) while (elt->parent && elt->parent->right == elt) elt = elt->parent; elt = elt->parent; - if (elt && tree_int_cst_lt (constructor_unfilled_index, + if (elt && !TREE_OVERFLOW_P (constructor_unfilled_index) + && tree_int_cst_lt (constructor_unfilled_index, elt->purpose)) { next = elt->purpose; diff --git gcc/testsuite/gcc.dg/large-size-array-7.c gcc/testsuite/gcc.dg/large-size-array-7.c new file mode 100644 index 0000000..196767d --- /dev/null +++ gcc/testsuite/gcc.dg/large-size-array-7.c @@ -0,0 +1,5 @@ +/* { dg-do compile { target "avr-*-*" } } */ +/* { dg-options "-O2" } */ +static char * name[] = { + [0xFFFFFF] = "bar" + }; /* { dg-error "too large" } */