From patchwork Thu Jul 4 19:00:20 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joern Rennecke X-Patchwork-Id: 256989 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 "localhost", Issuer "www.qmailtoaster.com" (not verified)) by ozlabs.org (Postfix) with ESMTPS id 1AC6E2C0091 for ; Fri, 5 Jul 2013 05:00:35 +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 :message-id:date:from:to:cc:subject:mime-version:content-type :content-transfer-encoding; q=dns; s=default; b=R3ptIKfr3l8nwg+C KWdjFnRrcZ34BmjQI0tD06wtkl/r1b2KRR6WWqklCewN06kfbC6sOon4yhJKBs1U il3egrVG9g+PFhs6aapZAIezzW7M6ikwk5ZNyhCfe0wD00rMS5nNpg2KbodGVHAe nXydgJW1cUriAyiuHauVRMQpxg4= 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 :message-id:date:from:to:cc:subject:mime-version:content-type :content-transfer-encoding; s=default; bh=511EonEAcpXrAtp2VZ0Wx+ HuVCA=; b=LrCTGPISjritUfZrelxqSVnKKipKvrDZPTGJjy3yyvZw+t5XgFcQSv 4UtqRJgesZw3SXkVJfsRLBjQSX41jRY4n2bo+yz00wtQ2a/TGYmpqI345S+g2J43 ymCJOAR02Z6J4mpgOe40sExNT99+w9N4PL1semijHaura2Lme4Wgk= Received: (qmail 15205 invoked by alias); 4 Jul 2013 19:00:29 -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 15161 invoked by uid 89); 4 Jul 2013 19:00:23 -0000 X-Spam-SWARE-Status: No, score=-1.6 required=5.0 tests=AWL, BAYES_20, KHOP_RCVD_UNTRUST, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from c62.cesmail.net (HELO c62.cesmail.net) (216.154.195.54) by sourceware.org (qpsmtpd/0.84/v0.84-167-ge50287c) with ESMTP; Thu, 04 Jul 2013 19:00:22 +0000 Received: from unknown (HELO epsilon2) ([192.168.1.60]) by c62.cesmail.net with ESMTP; 04 Jul 2013 15:00:20 -0400 Received: from cust213-dsl91-135-11.idnet.net (cust213-dsl91-135-11.idnet.net [91.135.11.213]) by webmail.spamcop.net (Horde MIME library) with HTTP; Thu, 04 Jul 2013 15:00:20 -0400 Message-ID: <20130704150020.lv606jwfogcckk0c-nzlynne@webmail.spamcop.net> Date: Thu, 04 Jul 2013 15:00:20 -0400 From: Joern Rennecke To: gcc-patches@gcc.gnu.org Cc: Richard Biener Subject: RFA: Fix c/57821 MIME-Version: 1.0 User-Agent: Internet Messaging Program (IMP) H3 (4.1.4) X-Virus-Found: No For this fix I've assumed that it is now the job of the various places that do calculations with sizetypes to flag overflows where this is desired. bootstrapped/regtested on i686-pc-linux-gnu . 2013-07-04 Joern Rennecke gcc: PR c/57821 * c/c-typeck.c (set_init_index): When folding, check for index overflow. * c-family/c-common.c (complete_array_type): Delay folding first index like other indices. When folding, check for index overflow. gcc/testsuite: PR c/57821 * gcc.dg/large-size-array-6.c: New test. Index: c/c-typeck.c =================================================================== --- c/c-typeck.c (revision 200606) +++ c/c-typeck.c (working copy) @@ -7217,6 +7217,8 @@ set_init_index (tree first, tree last, if (last) constant_expression_warning (last); constructor_index = convert (bitsizetype, first); + if (tree_int_cst_lt (constructor_index, first)) + TREE_OVERFLOW (constructor_index) = 1; if (last) { Index: c-family/c-common.c =================================================================== --- c-family/c-common.c (revision 200606) +++ c-family/c-common.c (working copy) @@ -9809,8 +9809,8 @@ complete_array_type (tree *ptype, tree i bool fold_p = false; if ((*v)[0].index) - maxindex = fold_convert_loc (input_location, sizetype, - (*v)[0].index); + maxindex = (*v)[0].index, fold_p = true; + curindex = maxindex; for (cnt = 1; vec_safe_iterate (v, cnt, &ce); cnt++) @@ -9821,15 +9821,28 @@ complete_array_type (tree *ptype, tree i else { if (fold_p) - curindex = fold_convert (sizetype, curindex); + { + /* Since we treat size types now as ordinary + unsigned types, we need an explicit overflow + check. */ + tree orig = curindex; + curindex = fold_convert (sizetype, curindex); + if (tree_int_cst_lt (curindex, orig)) + TREE_OVERFLOW (curindex) = 1; + } curindex = size_binop (PLUS_EXPR, curindex, size_one_node); } if (tree_int_cst_lt (maxindex, curindex)) maxindex = curindex, fold_p = curfold_p; } - if (fold_p) - maxindex = fold_convert (sizetype, maxindex); + if (fold_p) + { + tree orig = maxindex; + maxindex = fold_convert (sizetype, maxindex); + if (tree_int_cst_lt (maxindex, orig)) + TREE_OVERFLOW (maxindex) = 1; + } } } else Index: testsuite/gcc.dg/large-size-array-6.c =================================================================== --- testsuite/gcc.dg/large-size-array-6.c (revision 0) +++ testsuite/gcc.dg/large-size-array-6.c (working copy) @@ -0,0 +1,6 @@ +/* PR c/57821 */ +/* { dg-do compile } */ +/* { dg-options "-O2" } */ +static char * name[] = { + [0x8000000000000000] = "bar" + }; /* { dg-error "too large" } */