From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 66610 invoked by alias); 26 Jan 2018 23:21:10 -0000 Mailing-List: contact fortran-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Post: List-Help: , Sender: fortran-owner@gcc.gnu.org Received: (qmail 66592 invoked by uid 89); 26 Jan 2018 23:21:09 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-11.9 required=5.0 tests=BAYES_00,GIT_PATCH_2,GIT_PATCH_3,SPF_HELO_PASS,T_RP_MATCHES_RCVD autolearn=ham version=3.3.2 spammy=8gb, 8GB X-Spam-User: qpsmtpd, 2 recipients 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 ESMTP; Fri, 26 Jan 2018 23:21:08 +0000 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 0A758C0641E9; Fri, 26 Jan 2018 23:21:07 +0000 (UTC) Received: from tucnak.zalov.cz (ovpn-117-22.ams2.redhat.com [10.36.117.22]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 9DDDB609A9; Fri, 26 Jan 2018 23:21:06 +0000 (UTC) Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.15.2/8.15.2) with ESMTP id w0QNL33P001370; Sat, 27 Jan 2018 00:21:03 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.15.2/8.15.2/Submit) id w0QNL1V5001368; Sat, 27 Jan 2018 00:21:01 +0100 Date: Fri, 26 Jan 2018 23:21:00 -0000 From: Jakub Jelinek To: gcc-patches@gcc.gnu.org, fortran@gcc.gnu.org Subject: [PATCH] Avoid creating >= 8GB EXPR_CONSTANT initializers for ilp32 targets (PR fortran/84065) Message-ID: <20180126232101.GE2063@tucnak> Reply-To: Jakub Jelinek MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.9.1 (2017-09-22) X-SW-Source: 2018-01/txt/msg00191.txt.bz2 Hi! resolve_charlen is going to error on ilp32 target charlens above what can fit into 32-bit signed int, but add_init_expr_to_sym is done before resolve_charlen, allocating huge amounts of memory in those cases when we'll error later is just waste of compile time if running on 64-bit host with enough memory, or will unnecessarily ICE due to out of memory otherwise. Another option would be to emit the error resolve_charlen is going to emit and arrange for it not to be emitted afterwards, this just seemed to be easier. Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? It would be nice if the FE had some way to express very large repetitive EXPR_CONSTANT more efficiently, say by not allocating the memory for the rest which is filled only by ' ', or by allowing to say this and this is repeated after the initial portion this many times. 2018-01-26 Jakub Jelinek PR fortran/84065 * decl.c (add_init_expr_to_sym): Ignore initializers for too large lengths. --- gcc/fortran/decl.c.jj 2018-01-23 21:35:04.000000000 +0100 +++ gcc/fortran/decl.c 2018-01-26 18:24:22.064763299 +0100 @@ -1757,22 +1757,32 @@ add_init_expr_to_sym (const char *name, if (!gfc_specification_expr (sym->ts.u.cl->length)) return false; - HOST_WIDE_INT len = gfc_mpz_get_hwi (sym->ts.u.cl->length->value.integer); - - if (init->expr_type == EXPR_CONSTANT) - gfc_set_constant_character_len (len, init, -1); - else if (init->expr_type == EXPR_ARRAY) + int k = gfc_validate_kind (BT_INTEGER, gfc_charlen_int_kind, + false); + /* resolve_charlen will complain later on if the length + is too large. Just skeep the initialization in that case. */ + if (mpz_cmp (sym->ts.u.cl->length->value.integer, + gfc_integer_kinds[k].huge) <= 0) { - gfc_constructor *c; + HOST_WIDE_INT len + = gfc_mpz_get_hwi (sym->ts.u.cl->length->value.integer); + + if (init->expr_type == EXPR_CONSTANT) + gfc_set_constant_character_len (len, init, -1); + else if (init->expr_type == EXPR_ARRAY) + { + gfc_constructor *c; - /* Build a new charlen to prevent simplification from - deleting the length before it is resolved. */ - init->ts.u.cl = gfc_new_charlen (gfc_current_ns, NULL); - init->ts.u.cl->length = gfc_copy_expr (sym->ts.u.cl->length); + /* Build a new charlen to prevent simplification from + deleting the length before it is resolved. */ + init->ts.u.cl = gfc_new_charlen (gfc_current_ns, NULL); + init->ts.u.cl->length + = gfc_copy_expr (sym->ts.u.cl->length); - for (c = gfc_constructor_first (init->value.constructor); - c; c = gfc_constructor_next (c)) - gfc_set_constant_character_len (len, c->expr, -1); + for (c = gfc_constructor_first (init->value.constructor); + c; c = gfc_constructor_next (c)) + gfc_set_constant_character_len (len, c->expr, -1); + } } } } Jakub