From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 12974 invoked by alias); 2 May 2011 15:16:20 -0000 Received: (qmail 12965 invoked by uid 22791); 2 May 2011 15:16:19 -0000 X-SWARE-Spam-Status: No, hits=-3.3 required=5.0 tests=AWL,BAYES_00,T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from cantor2.suse.de (HELO mx2.suse.de) (195.135.220.15) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Mon, 02 May 2011 15:16:05 +0000 Received: from relay2.suse.de (charybdis-ext.suse.de [195.135.221.2]) by mx2.suse.de (Postfix) with ESMTP id A1FC186A2E; Mon, 2 May 2011 17:16:04 +0200 (CEST) Date: Mon, 02 May 2011 15:16:00 -0000 From: Richard Guenther To: gcc-patches@gcc.gnu.org Cc: "Joseph S. Myers" Subject: [PATCH][C] Change array size overflow check Message-ID: User-Agent: Alpine 2.00 (LNX 1167 2008-08-23) MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org X-SW-Source: 2011-05/txt/msg00080.txt.bz2 This changes the code that deals with too large array sizes to use int_fits_type_p instead of relying on the TREE_OVERFLOW setting of the tree folder. The latter will break once we don't treat sizetypes specially (and they keep being unsigned). Bootstrapped and tested on x86_64-unknown-linux-gnu, ok for trunk? Thanks, Richard. 2011-05-02 Richard Guenther * c-decl.c (grokdeclarator): Instead of looking at TREE_OVERFLOW check if the constant fits in the index type. Index: trunk/gcc/c-decl.c =================================================================== *** trunk.orig/gcc/c-decl.c 2011-05-02 14:50:36.000000000 +0200 --- trunk/gcc/c-decl.c 2011-05-02 15:12:15.000000000 +0200 *************** grokdeclarator (const struct c_declarato *** 5368,5382 **** convert (index_type, size_one_node)); ! /* If that overflowed, the array is too big. ??? ! While a size of INT_MAX+1 technically shouldn't ! cause an overflow (because we subtract 1), the ! overflow is recorded during the conversion to ! index_type, before the subtraction. Handling ! this case seems like an unnecessary ! complication. */ ! if (TREE_CODE (itype) == INTEGER_CST ! && TREE_OVERFLOW (itype)) { if (name) error_at (loc, "size of array %qE is too large", --- 5368,5380 ---- convert (index_type, size_one_node)); ! /* The above overflows when size does not fit ! in index_type. ! ??? While a size of INT_MAX+1 technically shouldn't ! cause an overflow (because we subtract 1), handling ! this case seems like an unnecessary complication. */ ! if (TREE_CODE (size) == INTEGER_CST ! && !int_fits_type_p (size, index_type)) { if (name) error_at (loc, "size of array %qE is too large",