From patchwork Tue Jul 6 16:10:17 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tobias Burnus X-Patchwork-Id: 58045 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 61B80B6EEF for ; Wed, 7 Jul 2010 02:10:52 +1000 (EST) Received: (qmail 27549 invoked by alias); 6 Jul 2010 16:10:45 -0000 Received: (qmail 27505 invoked by uid 22791); 6 Jul 2010 16:10:40 -0000 X-SWARE-Spam-Status: No, hits=-1.9 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_NONE X-Spam-Check-By: sourceware.org Received: from mx01.qsc.de (HELO mx01.qsc.de) (213.148.129.14) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Tue, 06 Jul 2010 16:10:33 +0000 Received: from [192.168.178.22] (port-92-204-41-181.dynamic.qsc.de [92.204.41.181]) by mx01.qsc.de (Postfix) with ESMTP id 42B4B3D6A5; Tue, 6 Jul 2010 18:10:18 +0200 (CEST) Message-ID: <4C335569.1030201@net-b.de> Date: Tue, 06 Jul 2010 18:10:17 +0200 From: Tobias Burnus User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.1.10) Gecko/20100520 SUSE/3.0.5 Thunderbird/3.0.5 MIME-Version: 1.0 To: gfortran , gcc patches Subject: [Patch, Fortran] PR 44742 - Avoid ICE when -fmax-array-constructor is exeeded 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 The patch adds a diagnostic for "constant" (F95, F2008; F2003: "initialization") expressions where the array constructor exceeds the limit given by -fmax-array-constructor -- thus fixing an ICE. The error message has been copied from array.c's gfc_expand_constructor. Thus, if you don't like it, one should change it there and in trans-array.c's gfc_conv_array_initializer as well. (Actually, I do not like the wording much, but did not immediately come up with something else.) Build and currently regtesting on x86-64-linux. OK for the trunk when it succeeded? * * * The patch (as posted in the PR) was approved by Jerry on IRC - I thus intent to commit it after regtesting finished. Tobias 2010-07-06 Tobias Burnus PR fortran/44742 * array.c (gfc_expand_constructor): Add optional diagnostic. * gfortran.h (gfc_expand_constructor): Update prototype. * expr.c (gfc_simplify_expr, check_init_expr, gfc_reduce_init_expr): Update gfc_expand_constructor call. * resolve.c (gfc_resolve_expr): Ditto. 2010-07-06 Tobias Burnus PR fortran/44742 * gfortran.dg/parameter_array_init_6.f90: New. diff --git a/gcc/fortran/array.c b/gcc/fortran/array.c index 64816f2..0c36f54 100644 --- a/gcc/fortran/array.c +++ b/gcc/fortran/array.c @@ -1545,7 +1545,7 @@ gfc_get_array_element (gfc_expr *array, int element) constructor if they are small enough. */ gfc_try -gfc_expand_constructor (gfc_expr *e) +gfc_expand_constructor (gfc_expr *e, bool fatal) { expand_info expand_save; gfc_expr *f; @@ -1557,6 +1557,15 @@ gfc_expand_constructor (gfc_expr *e) if (f != NULL) { gfc_free_expr (f); + if (fatal) + { + gfc_error ("The number of elements in the array constructor " + "at %L requires an increase of the allowed %d " + "upper limit. See -fmax-array-constructor " + "option", &e->where, + gfc_option.flag_max_array_constructor); + return FAILURE; + } return SUCCESS; } diff --git a/gcc/fortran/expr.c b/gcc/fortran/expr.c index c876fdd..12a46a9 100644 --- a/gcc/fortran/expr.c +++ b/gcc/fortran/expr.c @@ -1894,7 +1894,7 @@ gfc_simplify_expr (gfc_expr *p, int type) if (p->expr_type == EXPR_ARRAY && p->ref && p->ref->type == REF_ARRAY && p->ref->u.ar.type == AR_FULL) - gfc_expand_constructor (p); + gfc_expand_constructor (p, false); if (simplify_const_ref (p) == FAILURE) return FAILURE; @@ -2573,7 +2573,7 @@ check_init_expr (gfc_expr *e) if (t == FAILURE) break; - t = gfc_expand_constructor (e); + t = gfc_expand_constructor (e, true); if (t == FAILURE) break; @@ -2609,7 +2609,7 @@ gfc_reduce_init_expr (gfc_expr *expr) { if (gfc_check_constructor_type (expr) == FAILURE) return FAILURE; - if (gfc_expand_constructor (expr) == FAILURE) + if (gfc_expand_constructor (expr, true) == FAILURE) return FAILURE; } diff --git a/gcc/fortran/gfortran.h b/gcc/fortran/gfortran.h index 0c96bf4..a63f97e 100644 --- a/gcc/fortran/gfortran.h +++ b/gcc/fortran/gfortran.h @@ -2715,7 +2715,7 @@ gfc_try gfc_resolve_array_spec (gfc_array_spec *, int); int gfc_compare_array_spec (gfc_array_spec *, gfc_array_spec *); void gfc_simplify_iterator_var (gfc_expr *); -gfc_try gfc_expand_constructor (gfc_expr *); +gfc_try gfc_expand_constructor (gfc_expr *, bool); int gfc_constant_ac (gfc_expr *); int gfc_expanded_ac (gfc_expr *); gfc_try gfc_resolve_character_array_constructor (gfc_expr *); diff --git a/gcc/fortran/resolve.c b/gcc/fortran/resolve.c index 4e11fc6..a8ed544 100644 --- a/gcc/fortran/resolve.c +++ b/gcc/fortran/resolve.c @@ -5776,7 +5776,7 @@ gfc_resolve_expr (gfc_expr *e) { expression_rank (e); if (gfc_is_constant_expr (e) || gfc_is_expandable_expr (e)) - gfc_expand_constructor (e); + gfc_expand_constructor (e, false); } /* This provides the opportunity for the length of constructors with @@ -5786,7 +5786,7 @@ gfc_resolve_expr (gfc_expr *e) { /* For efficiency, we call gfc_expand_constructor for BT_CHARACTER here rather then add a duplicate test for it above. */ - gfc_expand_constructor (e); + gfc_expand_constructor (e, false); t = gfc_resolve_character_array_constructor (e); } --- /dev/null 2010-07-05 20:28:01.219304931 +0200 +++ b/gcc/testsuite/gfortran.dg/parameter_array_init_6.f90 2010-07-06 17:26:34.000000000 +0200 @@ -0,0 +1,18 @@ +! { dg-do compile } +! +! PR fortran/44742 +! +! Test case based on Juergen Reuter's and reduced by +! Janus Weil. +! +! The program creates a large array constructor, which +! exceeds -fmax-array-constructor - and caused an ICE. +! + +module proc8 + implicit none + integer, parameter :: N = 256 + logical, dimension(N**2), parameter :: A = .false. + logical, dimension(N,N), parameter :: B & + = reshape ( (/ A /), (/ N, N /) ) ! { dg-error "array constructor at .1. requires an increase" } +end module