From patchwork Wed Sep 8 23:06:03 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Hubicka X-Patchwork-Id: 64239 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 B71C1B70A8 for ; Thu, 9 Sep 2010 09:06:15 +1000 (EST) Received: (qmail 27565 invoked by alias); 8 Sep 2010 23:06:13 -0000 Received: (qmail 27554 invoked by uid 22791); 8 Sep 2010 23:06:11 -0000 X-SWARE-Spam-Status: No, hits=-1.8 required=5.0 tests=AWL, BAYES_00, T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from nikam-dmz.ms.mff.cuni.cz (HELO nikam.ms.mff.cuni.cz) (195.113.20.16) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Wed, 08 Sep 2010 23:06:05 +0000 Received: from localhost (occam.ms.mff.cuni.cz [195.113.18.121]) by nikam.ms.mff.cuni.cz (Postfix) with ESMTP id 2DC179AC29B; Thu, 9 Sep 2010 01:06:03 +0200 (CEST) Received: by localhost (Postfix, from userid 16202) id 235A756415F; Thu, 9 Sep 2010 01:06:03 +0200 (CEST) Date: Thu, 9 Sep 2010 01:06:03 +0200 From: Jan Hubicka To: gcc-patches@gcc.gnu.org, rguenther@suse.de Subject: PR tree-optimization/45598 (build_int_cst_wide ICE) Message-ID: <20100908230602.GA21068@kam.mff.cuni.cz> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.18 (2008-05-17) 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 Hi, this patch fix ICE when we try to fold array_ref of string where result itself is array of size 1. We might actually fold this into one element constructor, but we seem to be folding this well the other way around - first folding the nested array references and then fold into the actual value. Bootstrapped/regtested x86_64-linux, OK? Honza PR tree-optimize/45598 * tree-ssa-ccp.c (fold_const_aggregate_ref): Check that result of string folding is of integral type. * fortran.fortran-torture/compile/pr45598.f90: New test. Index: testsuite/gfortran.fortran-torture/compile/pr45598.f90 =================================================================== --- testsuite/gfortran.fortran-torture/compile/pr45598.f90 (revision 0) +++ testsuite/gfortran.fortran-torture/compile/pr45598.f90 (revision 0) @@ -0,0 +1,13 @@ +program main +implicit none +character(len=10) :: digit_string = '123456789' +character :: digit_arr(10) +call copy(digit_string, digit_arr) +print '(1x, a1)',digit_arr(1:9) +contains + subroutine copy(in, out) + character, dimension(10) :: in, out + out(1:10) = in(1:10) + end subroutine copy +end program main + Index: tree-ssa-ccp.c =================================================================== --- tree-ssa-ccp.c (revision 164002) +++ tree-ssa-ccp.c (working copy) @@ -1398,8 +1397,7 @@ fold_const_aggregate_ref (tree t) } /* Fold read from constant string. */ - if (TREE_CODE (ctor) == STRING_CST - && TREE_CODE (idx) == INTEGER_CST) + if (TREE_CODE (ctor) == STRING_CST) { tree low_bound = array_ref_low_bound (t); double_int low_bound_cst; @@ -1407,7 +1405,9 @@ fold_const_aggregate_ref (tree t) double_int length_cst; bool signed_p = TYPE_UNSIGNED (TREE_TYPE (idx)); - if (TREE_CODE (low_bound) != INTEGER_CST) + if (TREE_CODE (idx) != INTEGER_CST + || !INTEGRAL_TYPE_P (TREE_TYPE (t)) + || TREE_CODE (low_bound) != INTEGER_CST) return NULL_TREE; low_bound_cst = tree_to_double_int (low_bound); index_cst = tree_to_double_int (idx);