From patchwork Thu Jul 3 10:18:24 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marek Polacek X-Patchwork-Id: 366823 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.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id D6FA614007B for ; Thu, 3 Jul 2014 20:18:41 +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=HmREdRzmC5BmcY4aN mKhqP8PoN5kdA1QKuqkAHcKyu9V7Bav28GWcs9IVOJ4ru0kr9hKjQGpqQrWRsGFk a6LbUNXHWzBbeY+LAK5tHr4imm867bfNHauXkro0KtotZWVonaNd0sowC5X6AepT uw0tH/Fc3jNuNu3V6EEtm7izyw= 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=mnbLlYlyuBoysjai01mIgkt 3FXs=; b=jtgs3TpZaaRLrrs679hlw+3+A2/CG9fFGf/kkfEmZLCOURxExfGT5tp WyagtfSJZFJDbS0iZvOmdiwuvy5QDo2v2/KIN1pB04GWqV0OzTJ+GT4gsf2FycIt w9dwYihZtag00YkrYPeXblzTMFRgzGBwN2t1HAe3tKXw0mC8/FJg= Received: (qmail 5023 invoked by alias); 3 Jul 2014 10:18:34 -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 5005 invoked by uid 89); 3 Jul 2014 10:18:33 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.7 required=5.0 tests=AWL, BAYES_00, SPF_HELO_PASS, SPF_PASS, T_RP_MATCHES_RCVD autolearn=ham version=3.3.2 X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-GCM-SHA384 encrypted) ESMTPS; Thu, 03 Jul 2014 10:18:30 +0000 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id s63AIRjK018778 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 3 Jul 2014 06:18:28 -0400 Received: from redhat.com (ovpn-116-50.ams2.redhat.com [10.36.116.50]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id s63AIOMW017781 (version=TLSv1/SSLv3 cipher=AES128-GCM-SHA256 bits=128 verify=NO); Thu, 3 Jul 2014 06:18:26 -0400 Date: Thu, 3 Jul 2014 12:18:24 +0200 From: Marek Polacek To: Mike Stump Cc: Jeff Law , GCC Patches Subject: Re: [PATCH] Don't ICE with huge alignment (PR middle-end/60226) Message-ID: <20140703101823.GL20427@redhat.com> References: <20140304164029.GN16545@redhat.com> <53B1BF74.2060801@redhat.com> <53648E99-800C-455B-B975-CD9BB4BEF1CD@comcast.net> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <53648E99-800C-455B-B975-CD9BB4BEF1CD@comcast.net> User-Agent: Mutt/1.5.23 (2014-03-12) On Mon, Jun 30, 2014 at 03:40:18PM -0700, Mike Stump wrote: > I glanced at it: > > (gdb) p/x TYPE_ALIGN (type) > $1 = 2147483648 > (gdb) p/x TYPE_ALIGN (type) > $2 = 0x80000000 > > The callee is int, the caller uses unsigned int. The assert I see is because the routines are not type correct: > > => TYPE_SIZE (type) = round_up (TYPE_SIZE (type), TYPE_ALIGN (type)); > > (gdb) ptype TYPE_ALIGN (type) > type = unsigned int > > > tree > round_up_loc (location_t loc, tree value, int divisor) > { > tree div = NULL_TREE; > > =>gcc_assert (divisor > 0); > > Would be nice if the routine was type correct (wrt unsigned). Yeah, I did that. One issue with that is that round_up now wraps the value, so I had to add a check for huge size before rounding up, otherwise we'd regress on e.g. PR42611. How about the following? Bootstrapped/regtested on x86_64-linux, ok for trunk? 2014-07-03 Marek Polacek PR c/60226 * fold-const.c (round_up_loc): Change the parameter type. Remove assert. * fold-const.h (round_up_loc): Adjust declaration. * stor-layout.c (finalize_record_size): Check for too large types. * c-c++-common/pr60226.c: New test. Marek diff --git gcc/fold-const.c gcc/fold-const.c index d22eac1..c57ac7b 100644 --- gcc/fold-const.c +++ gcc/fold-const.c @@ -16647,11 +16647,10 @@ fold_ignored_result (tree t) /* Return the value of VALUE, rounded up to a multiple of DIVISOR. */ tree -round_up_loc (location_t loc, tree value, int divisor) +round_up_loc (location_t loc, tree value, unsigned int divisor) { tree div = NULL_TREE; - gcc_assert (divisor > 0); if (divisor == 1) return value; diff --git gcc/fold-const.h gcc/fold-const.h index dcb97a1..3b5fd84 100644 --- gcc/fold-const.h +++ gcc/fold-const.h @@ -144,7 +144,7 @@ extern tree combine_comparisons (location_t, enum tree_code, enum tree_code, extern void debug_fold_checksum (const_tree); extern bool may_negate_without_overflow_p (const_tree); #define round_up(T,N) round_up_loc (UNKNOWN_LOCATION, T, N) -extern tree round_up_loc (location_t, tree, int); +extern tree round_up_loc (location_t, tree, unsigned int); #define round_down(T,N) round_down_loc (UNKNOWN_LOCATION, T, N) extern tree round_down_loc (location_t, tree, int); extern tree size_int_kind (HOST_WIDE_INT, enum size_type_kind); diff --git gcc/stor-layout.c gcc/stor-layout.c index cfd436f..19e7adb 100644 --- gcc/stor-layout.c +++ gcc/stor-layout.c @@ -1587,6 +1587,11 @@ finalize_record_size (record_layout_info rli) unpadded_size_unit = size_binop (PLUS_EXPR, unpadded_size_unit, size_one_node); + if (TREE_CODE (unpadded_size_unit) == INTEGER_CST + && !TREE_OVERFLOW (unpadded_size_unit) + && !valid_constant_size_p (unpadded_size_unit)) + error ("type %qT is too large", rli->t); + /* Round the size up to be a multiple of the required alignment. */ TYPE_SIZE (rli->t) = round_up (unpadded_size, TYPE_ALIGN (rli->t)); TYPE_SIZE_UNIT (rli->t) diff --git gcc/testsuite/c-c++-common/pr60226.c gcc/testsuite/c-c++-common/pr60226.c index e69de29..3a1c261 100644 --- gcc/testsuite/c-c++-common/pr60226.c +++ gcc/testsuite/c-c++-common/pr60226.c @@ -0,0 +1,14 @@ +/* PR c/60226 */ +/* { dg-do compile } */ +/* { dg-options "-Wno-c++-compat" { target c } } */ + +typedef int __attribute__ ((aligned (1 << 28))) int28; +int28 foo[4] = {}; /* { dg-error "alignment of array elements is greater than element size" } */ +typedef int __attribute__ ((aligned (1 << 29))) int29; /* { dg-error "requested alignment is too large" } */ + +void +f (void) +{ + struct { __attribute__((aligned (1 << 28))) double a; } x1; + struct { __attribute__((aligned (1 << 29))) double a; } x2; /* { dg-error "requested alignment is too large" } */ +}