From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from esa2.mentor.iphmx.com (esa2.mentor.iphmx.com [68.232.141.98]) by sourceware.org (Postfix) with ESMTPS id 91E7B3857817; Wed, 10 Mar 2021 10:06:23 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 91E7B3857817 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=codesourcery.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=Tobias_Burnus@mentor.com IronPort-SDR: /qzp+qNN57ayKYf+LlOpbwkeuBOHEAJzcvoa/KzFAmEDs5n9Xm9zO70A5oAZ/xVWujGOyUtsiH 9m0QWXaQSt2XJ0NRIPx0xtJo0kE4SbPBI+ivKq/HYvPG2wujtLZPmJCf7JFY/cJKDtB6QCkDUA /XhxufosPAd82vSojqRVHGvFBT6QTeJO+VW9CQd1tVqyJJb4rqEvI+flADmz4HK/6hrm6tnpf7 Gh7hibN6lpKwXyzEN8//UaM6DnCElvUIc/5Z99KekDucZW1HEB3u3sCrLuGarVDyuRrevG4V4c cqI= X-IronPort-AV: E=Sophos;i="5.81,237,1610438400"; d="scan'208";a="58938115" Received: from orw-gwy-02-in.mentorg.com ([192.94.38.167]) by esa2.mentor.iphmx.com with ESMTP; 10 Mar 2021 02:06:22 -0800 IronPort-SDR: sCaEmFMexiUsTY/fVotCOuYEQ212N3afIpBjoqxyHeUAqsx9VNajIzULQAn8LvGei6cniYtnSS C1YyDihlownQTReulNQ8IfP7Bn0m3oo99lZiFt+ejphsRQ/BdXI5kYViuKaoMinztFhilTPAKp JWuVwQvT4FgcRKx1rMkbEpdbOFr67l4uXjYWwydrOdg30qmjZZPVhRUz9izRSSWkcVgjzEXpYe JLTHKcu05L/L/DEQ9Ll3Wj+XCbQZnHeYel9EGZv+q3fV4DYRls2Px5yiF3aHrqplS3Phn4fyiT MSU= Subject: Re: [PATCH] PR fortran/99205 - [10/11 Regression] Out of memory with undefined character length To: Harald Anlauf , fortran , gcc-patches References: From: Tobias Burnus Message-ID: <8a63eb89-91e6-1e8d-870e-8a2f7a6750df@codesourcery.com> Date: Wed, 10 Mar 2021 11:06:16 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.8.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset="utf-8"; format=flowed Content-Transfer-Encoding: quoted-printable Content-Language: en-US X-Originating-IP: [137.202.0.90] X-ClientProxiedBy: svr-ies-mbx-01.mgc.mentorg.com (139.181.222.1) To svr-ies-mbx-01.mgc.mentorg.com (139.181.222.1) X-Spam-Status: No, score=-12.1 required=5.0 tests=BAYES_00, GIT_PATCH_0, HEADER_FROM_DIFFERENT_DOMAINS, KAM_DMARC_STATUS, NICE_REPLY_A, RCVD_IN_DNSWL_NONE, SPF_HELO_PASS, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: fortran@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Fortran mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 10 Mar 2021 10:06:25 -0000 Dear Harald, dear all, On 09.03.21 20:45, Harald Anlauf via Fortran wrote: > character variables with undefined length are not allowed as > objects in DATA statements. We better reject them. > > Regtested on x86_64-pc-linux-gnu. OK for master / backport? > > PR fortran/99205 - Out of memory with undefined character length > > A variable that is a data statement object shall be a designator, > thus a character variable shall have a constant length. This comment is wrong: A designator does not imply this =E2=80=93 nor is F2018:C875 violated, not even the substring starting/ending point const expr bit. The reason that it is not permitted is the "automatic data object" (see *...* highlighted parts in the quote): C876 (R839) A *variable* whose *designator* appears as a *data-stmt-object* or a data-i-do-object hall not be a dummy argument, accessed by use or host association, in a named common block unless the DATA statement is in a block data program unit, in blank common, a function name, a function result name, an *automatic* *data* *object,* or an allocatable variable. With the definition: "3.11 automatic data object nondummy data object with a type parameter or array bound that depends on the value of aspecification-expr that is not a constant expression (8.3)" In the following variant of the program, the invalid variable declaration of 'c' itself is avoided by using a block: integer :: ll ll =3D 4 block character(ll) :: c(2), cc(2) character(ll) :: c2(2), cc2(2) data c /'a', 'b'/ data c2(:)(1:1) /'a', 'b'/ common /block/ cc, cc2 end block end You may consider to update your testcase or to augment your testcase. The patch itself is OK, but you really need to update the commit description. Tobias > > gcc/fortran/ChangeLog: > > PR fortran/99205 > * data.c (gfc_assign_data_value): Reject non-constant character > length for lvalue. > > gcc/testsuite/ChangeLog: > > PR fortran/99205 > * gfortran.dg/pr99205.f90: New test. > > > pr99205.patch > > diff --git a/gcc/fortran/data.c b/gcc/fortran/data.c > index 25e97930169..71e2552025d 100644 > --- a/gcc/fortran/data.c > +++ b/gcc/fortran/data.c > @@ -595,6 +595,9 @@ gfc_assign_data_value (gfc_expr *lvalue, gfc_expr *rv= alue, mpz_t index, > /* An initializer has to be constant. */ > if (lvalue->ts.u.cl->length =3D=3D NULL && !(ref && ref->u.ss.len= gth !=3D NULL)) > return false; > + if (lvalue->ts.u.cl->length > + && lvalue->ts.u.cl->length->expr_type !=3D EXPR_CONSTANT) > + return false; > expr =3D create_character_initializer (init, last_ts, ref, rvalue= ); > if (!expr) > return false; > diff --git a/gcc/testsuite/gfortran.dg/pr99205.f90 b/gcc/testsuite/gfortr= an.dg/pr99205.f90 > new file mode 100644 > index 00000000000..ed0782ce8a0 > --- /dev/null > +++ b/gcc/testsuite/gfortran.dg/pr99205.f90 > @@ -0,0 +1,11 @@ > +! { dg-do compile } > +! PR fortran/99205 - Out of memory with undefined character length > +! { dg-options "-w" } > + > +program p > + character(l) :: c(2) ! { dg-error "must have constant character length= " } > + data c /'a', 'b'/ > + common c > +end > + > +! { dg-error "cannot appear in the expression at" " " { target *-*-* } 6= } ----------------- Mentor Graphics (Deutschland) GmbH, Arnulfstrasse 201, 80634 M=C3=BCnchen R= egistergericht M=C3=BCnchen HRB 106955, Gesch=C3=A4ftsf=C3=BChrer: Thomas H= eurung, Frank Th=C3=BCrauf