From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 24151 invoked by alias); 5 Sep 2011 14:07:30 -0000 Received: (qmail 24138 invoked by uid 22791); 5 Sep 2011 14:07:29 -0000 X-SWARE-Spam-Status: No, hits=-2.9 required=5.0 tests=ALL_TRUSTED,AWL,BAYES_00 X-Spam-Check-By: sourceware.org Received: from localhost (HELO gcc.gnu.org) (127.0.0.1) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Mon, 05 Sep 2011 14:07:16 +0000 From: "rguenth at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug ada/50294] ICE in output_constructor_regular_field, at varasm.c:4751 Date: Mon, 05 Sep 2011 14:07:00 -0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: ada X-Bugzilla-Keywords: ice-on-valid-code, wrong-code X-Bugzilla-Severity: normal X-Bugzilla-Who: rguenth at gcc dot gnu.org X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Changed-Fields: Message-ID: In-Reply-To: References: X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated Content-Type: text/plain; charset="UTF-8" MIME-Version: 1.0 Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org X-SW-Source: 2011-09/txt/msg00324.txt.bz2 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=50294 --- Comment #2 from Richard Guenther 2011-09-05 14:06:57 UTC --- Index: gcc/varasm.c =================================================================== --- gcc/varasm.c (revision 178527) +++ gcc/varasm.c (working copy) @@ -4746,9 +4746,13 @@ output_constructor_regular_field (oc_loc if (local->index != NULL_TREE) { + /* Perform the index calculation in modulo arithmetic but + sign-extend the result because Ada has negative DECL_FIELD_OFFSETs + but we are using an unsigned sizetype. */ + unsigned prec = TYPE_PRECISION (sizetype); double_int idx = double_int_sub (tree_to_double_int (local->index), tree_to_double_int (local->min_index)); - gcc_assert (double_int_fits_in_shwi_p (idx)); + idx = double_int_sext (idx, prec); fieldpos = (tree_low_cst (TYPE_SIZE_UNIT (TREE_TYPE (local->val)), 1) * idx.low); } fixes this, but loses the check for index - min_index overflowing a HWI (arguably that should have been detected earlier in the FEs). Fact is we lose information when forcing offsets / indices to an unsigned type.