From patchwork Fri Sep 2 14:31:50 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Biener X-Patchwork-Id: 113147 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 1B1FDB6F83 for ; Sat, 3 Sep 2011 00:32:21 +1000 (EST) Received: (qmail 25213 invoked by alias); 2 Sep 2011 14:32:18 -0000 Received: (qmail 25205 invoked by uid 22791); 2 Sep 2011 14:32:16 -0000 X-SWARE-Spam-Status: No, hits=-3.5 required=5.0 tests=AWL, BAYES_00, 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; Fri, 02 Sep 2011 14:31:52 +0000 Received: from relay2.suse.de (charybdis-ext.suse.de [195.135.221.2]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mx2.suse.de (Postfix) with ESMTP id 954498A908; Fri, 2 Sep 2011 16:31:50 +0200 (CEST) Date: Fri, 2 Sep 2011 16:31:50 +0200 (CEST) From: Richard Guenther To: gcc-patches@gcc.gnu.org Cc: Eric Botcazou Subject: Re: [PATCH][Ada][C][C++] sizetypes no longer sign-extend In-Reply-To: Message-ID: References: User-Agent: Alpine 2.00 (LNX 1167 2008-08-23) MIME-Version: 1.0 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 On Fri, 2 Sep 2011, Richard Guenther wrote: > > This patch makes us no longer treat unsigned sizetypes as sign-extending > which has caused trouble in the past (see the tree-ssa-ccp.c workarounds > removed below). > > Most frontend specific changes below deal with the fact that overflow > behavior, as reported from size_binop, changes as unsigned sizetypes > now no longer overflow at SSIZETYPE_MAX but at USIZETYPE_MAX. Diagnostics > expect warnings when overflow at half of the address-space occurs, > and Ada needs to pay special attention to its "negative" offsets, > all host_integerp (..., 1) checks have to be adjusted. > > The patch bootstraps ok on x86_64-unknown-linux-gnu with all languages > enabled and tests with the following FAILs with {,-m32}: > > Running target unix//-m32 > FAIL: g++.dg/tree-ssa/pr19807.C scan-tree-dump-times optimized "\\+ > 0x0f*;" 1 > > still need to figure out how to properly quote that regexp for TCL > scanning for the various (sizetype)-1U printings ... > > Running target unix/{,-m32} > FAIL: gcc.dg/pr42611.c (test for errors, line 17) > FAIL: gcc.dg/pr42611.c (test for excess errors) > > another missed overflow check, looking at it now > > Running target unix/ > FAIL: gnat.dg/array11.adb (test for warnings, line 12) > FAIL: gnat.dg/object_overflow.adb (test for warnings, line 8) > > Running target unix//-m32 > FAIL: gnat.dg/array11.adb (test for warnings, line 12) > FAIL: gnat.dg/frame_overflow.adb (test for errors, line 17) > FAIL: gnat.dg/frame_overflow.adb (test for errors, line 24) > FAIL: gnat.dg/object_overflow.adb (test for warnings, line 8) > > probably similar, I pushed back Ada diagnostic tests for now, > but will look at them after resolving the above remaining FAIL. gnat.dg/array11.adb and gnat.dg/object_overflow.adb are fixed by the following. Not sure what type to test TYPE_UNSIGNED on though. Possibly needs adjustment in c-comment.c:complete_array_type to use ssize_int (-1) for the array[] = {...} case. Comments? Thanks, Richard. Index: trunk/gcc/stor-layout.c =================================================================== --- trunk.orig/gcc/stor-layout.c 2011-09-02 16:23:33.000000000 +0200 +++ trunk/gcc/stor-layout.c 2011-09-02 16:19:12.000000000 +0200 @@ -1959,16 +1959,14 @@ layout_type (tree type) if (integer_zerop (element_size)) length = size_zero_node; - /* The computation should happen in the original type so + /* The computation should happen in the original signedness so that (possible) negative values are handled appropriately. */ else length = fold_convert (sizetype, - fold_build2 (PLUS_EXPR, TREE_TYPE (lb), - build_int_cst (TREE_TYPE (lb), 1), - fold_build2 (MINUS_EXPR, - TREE_TYPE (lb), - ub, lb))); + size_binop (PLUS_EXPR, + build_int_cst (TREE_TYPE (lb), 1), + size_binop (MINUS_EXPR, ub, lb))); TYPE_SIZE (type) = size_binop (MULT_EXPR, element_size, fold_convert (bitsizetype, Index: trunk/gcc/ada/gcc-interface/utils.c =================================================================== --- trunk.orig/gcc/ada/gcc-interface/utils.c 2011-09-02 16:23:33.000000000 +0200 +++ trunk/gcc/ada/gcc-interface/utils.c 2011-09-02 16:22:20.000000000 +0200 @@ -1248,7 +1248,7 @@ copy_type (tree type) return new_type; } -/* Return a subtype of sizetype with range MIN to MAX and whose +/* Return a subtype of [s]sizetype with range MIN to MAX and whose TYPE_INDEX_TYPE is INDEX. GNAT_NODE is used for the position of the associated TYPE_DECL. */ @@ -1256,7 +1256,8 @@ tree create_index_type (tree min, tree max, tree index, Node_Id gnat_node) { /* First build a type for the desired range. */ - tree type = build_nonshared_range_type (sizetype, min, max); + tree type = build_nonshared_range_type (TYPE_UNSIGNED (index) + ? sizetype : ssizetype, min, max); /* Then set the index type. */ SET_TYPE_INDEX_TYPE (type, index);