From patchwork Fri Feb 8 20:36:59 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Harald Anlauf X-Patchwork-Id: 1038947 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-495540-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=gmx.de Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="jXOmL3yS"; dkim-atps=neutral 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 43x6S5652Fz9sN1 for ; Sat, 9 Feb 2019 07:37:24 +1100 (AEDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :message-id:date:from:mime-version:to:subject:content-type; q= dns; s=default; b=st36WerW4M1g7AftjT+kaG5m/6kl3bagswxDw31rf/XTOc aP8jB9ah+vfOhJse6hFS0AqV0l4lM/NawKZCLMhrRK+hPdOBnpZsYwiA65DjUE9m +t/ncOwQpVEvl32kYjTcZ/3a+EtR/nhGKgghGYPgzHbbM/5SCHhY0JUkWJ0iQ= 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 :message-id:date:from:mime-version:to:subject:content-type; s= default; bh=UZ49erqsO6u+qtZuzdl5N+rwGAo=; b=jXOmL3ySLco7fXTKExsG zML6F8z3YQNF3C9Ln/qojm2uwSY4zoKXkWLWnzPxdPdkSVPY6K0peHF/R4Y15otz tL/HM8oVhsyxEHUC/QeTAZpEiWxF7XB9XMtq8OdP3FS1vBAsYSUt6B+T2RB7UNsq 9YcO55X123x69gh+EeYKrQg= Received: (qmail 99348 invoked by alias); 8 Feb 2019 20:37:07 -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 99257 invoked by uid 89); 8 Feb 2019 20:37:06 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-11.8 required=5.0 tests=BAYES_00, FREEMAIL_FROM, GIT_PATCH_2, GIT_PATCH_3, KAM_ASCII_DIVIDERS, RCVD_IN_DNSWL_LOW, SPF_PASS autolearn=ham version=3.3.2 spammy=simplification, transfer X-HELO: mout.gmx.net Received: from mout.gmx.net (HELO mout.gmx.net) (212.227.15.15) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 08 Feb 2019 20:37:04 +0000 Received: from proton.at.home ([93.207.82.4]) by mail.gmx.com (mrgmx002 [212.227.17.190]) with ESMTPSA (Nemesis) id 0MTjua-1gjIuT12ky-00QTq4; Fri, 08 Feb 2019 21:37:01 +0100 Message-ID: <5C5DE86B.7060009@gmx.de> Date: Fri, 08 Feb 2019 21:36:59 +0100 From: Harald Anlauf User-Agent: Mozilla/5.0 (X11; Linux i686; rv:17.0) Gecko/20130329 Thunderbird/17.0.5 MIME-Version: 1.0 To: gfortran , gcc-patches Subject: [PR fortran/89077, patch, part 2] - ICE using * as len specifier for character parameter The attached patch attempts a substring length simplification so that more complex expressions are handled in initialization expressions. Thanks to Thomas König for the suggestion. Regtested on x86_64-pc-linux-gnu. (The PR still has other wrong-code issue to be addressed separately.) OK for trunk? And for backports to 8/7? Thanks, Harald 2019-02-08 Harald Anlauf PR fortran/89077 * resolve.c (gfc_resolve_substring_charlen): Check substring length for constantness prior to general calculation of length. 2019-02-08 Harald Anlauf PR fortran/89077 * gfortran.dg/substr_simplify.f90: New test. Index: gcc/testsuite/gfortran.dg/substr_simplify.f90 =================================================================== --- gcc/testsuite/gfortran.dg/substr_simplify.f90 (nonexistent) +++ gcc/testsuite/gfortran.dg/substr_simplify.f90 (working copy) @@ -0,0 +1,20 @@ +! { dg-do run } +! +! Test fixes for substring simplications derived from +! PR fortran/89077 - ICE using * as len specifier for character parameter + +program test + implicit none + integer :: i + character(*), parameter :: s = 'abcdef', y = 'efcdab' + character(6), save :: t = transfer ([(s(i:i), i=1,len(s) )], s) + character(*), parameter :: u = transfer ([(s(i:i+2),i=1,len(s),3)], s) + character(6), save :: v = transfer ([(s(i:i+2),i=1,len(s),3)], s) + character(*), parameter :: w = transfer ([(y(i:i+1),i=len(s)-1,1,-2)], s) + character(6), save :: x = transfer ([(y(i:i+1),i=len(s)-1,1,-2)], s) + if (len (t) /= len (s) .or. t /= s) stop 1 + if (len (u) /= len (s) .or. u /= s) stop 2 + if (len (v) /= len (s) .or. v /= s) stop 3 + if (len (w) /= len (s) .or. w /= s) stop 4 + if (len (x) /= len (s) .or. x /= s) stop 5 +end Index: gcc/fortran/resolve.c =================================================================== --- gcc/fortran/resolve.c (revision 268658) +++ gcc/fortran/resolve.c (working copy) @@ -4965,6 +4965,7 @@ gfc_ref *char_ref; gfc_expr *start, *end; gfc_typespec *ts = NULL; + mpz_t diff; for (char_ref = e->ref; char_ref; char_ref = char_ref->next) { @@ -5016,12 +5017,25 @@ return; } - /* Length = (end - start + 1). */ - e->ts.u.cl->length = gfc_subtract (end, start); - e->ts.u.cl->length = gfc_add (e->ts.u.cl->length, - gfc_get_int_expr (gfc_charlen_int_kind, - NULL, 1)); + /* Length = (end - start + 1). + Check first whether it has a constant length. */ + if (gfc_dep_difference (end, start, &diff)) + { + gfc_expr *len = gfc_get_constant_expr (BT_INTEGER, gfc_charlen_int_kind, + &e->where); + mpz_add_ui (len->value.integer, diff, 1); + mpz_clear (diff); + e->ts.u.cl->length = len; + } + else + { + e->ts.u.cl->length = gfc_subtract (end, start); + e->ts.u.cl->length = gfc_add (e->ts.u.cl->length, + gfc_get_int_expr (gfc_charlen_int_kind, + NULL, 1)); + } + /* F2008, 6.4.1: Both the starting point and the ending point shall be within the range 1, 2, ..., n unless the starting point exceeds the ending point, in which case the substring has length zero. */