From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mout.gmx.net (mout.gmx.net [212.227.17.21]) by sourceware.org (Postfix) with ESMTPS id C5436385ED4A; Wed, 10 Mar 2021 21:26:42 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org C5436385ED4A X-UI-Sender-Class: 01bb95c1-4bf8-414a-932a-4f6e2808ef9c Received: from [93.207.91.224] ([93.207.91.224]) by web-mail.gmx.net (3c-app-gmx-bs58.server.lan [172.19.170.142]) (via HTTP); Wed, 10 Mar 2021 22:26:38 +0100 MIME-Version: 1.0 Message-ID: From: Harald Anlauf To: Tobias Burnus Cc: fortran , gcc-patches Subject: Re: [PATCH] PR fortran/99205 - [10/11 Regression] Out of memory with undefined character length Content-Type: multipart/mixed; boundary=sgnirk-4aa5439d-d9f4-40b1-989e-4730c4675d2a Date: Wed, 10 Mar 2021 22:26:38 +0100 Importance: normal Sensitivity: Normal In-Reply-To: <8a63eb89-91e6-1e8d-870e-8a2f7a6750df@codesourcery.com> References: <8a63eb89-91e6-1e8d-870e-8a2f7a6750df@codesourcery.com> X-UI-Message-Type: mail X-Priority: 3 X-Provags-ID: V03:K1:aXe5j9vFHGmUF3PWyjhhKgYG8V1YXGcBnX/1kARehcEpiYRvEEQ5UVrp4y/FX9iJLrPyH rv6uLtReOjz16/WK6VIvVEZsdb/EaC/vDWL7NShtPm+qTMJh3npEFy4fTUjA6QXDrIVjoeGqoE8z kLbk/UNDy5hEt8+yBV6uHf1aeVcFCo8ybmv98FDEaUPzs9/2CS8xJady+QTs4nGVlqBwI+eNfleG UzqbmphhrRF0hv+scrDGsXP0hj7hZLPwsQimMAvV5ylpU3lEOC2lWII2KPCj25mQxOXyWI1DtqjA lE= X-UI-Out-Filterresults: notjunk:1;V03:K0:08T0yY8U9M8=:GoGKGHSOkYMqMZ7Av8bOv/ E/pUEzSgZxc5P0pQCdKBl6yeHIA6RD3x4yvHyIYpwUevFcAXGfgUwzp00HQV5vm37r1/vTnyd eWN3tlJz58qO4ncKbf7PEaVsZ+YaPyDprjgiL20/5CfMbGybF2vgGn32XaJRrqP7EExskTjmD 9JZ2KROqeUHNJXd8cfvyI8wbmgiMc6kPWPzWeHBaif1DSicnK10okCKyeXZQQ6PbqiD2bdzWw mYLiyKam/Rr1METzEHARsjaM/DuoyE4khXSuNwZRiM6WifNmN+z4z9HxMq4eYlwnNwafcxlCk RWTUsOIM6QW2oEdQgrTv4/IchvMxr7EiaDl6nPkuiAz2BuApFPJl6vWXnQd8K5gTEMv/A6bF0 laomItWPTjGMG+uHwrjoXq4qEROJvQK5qkztyb3mCEC8zNaqu93hfxYuzapbCp0fTeBX7zRkt Mt8jy9DP9zp9FEJ1WQlHasM/fBbtRVQeDkErhh6L0bZfbI9kE6BRd/Faqu4XUhE4c9F7/mcCV E6IwUEwUEat4xxHfyqEfFc8BlN1OB0Jy2h60kGtEP3favae3jHmJPEgFZe3jSzauAHxEqqvSp /4gUJHJhVJ0Z8= X-Spam-Status: No, score=-4.7 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, FREEMAIL_FROM, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, 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 21:26:44 -0000 --sgnirk-4aa5439d-d9f4-40b1-989e-4730c4675d2a Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Dear Tobias, all, > 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)" inspired by Tobias' (although invalid) code example I found another testcase which lead to trouble during error recovery due to a NULL pointer dereference. Here's the updated changelog for the updated patch (attached). I also renamed the first testcase so that they fit better to the existing scheme. Again regtested on x86_64-pc-linux-gnu. Now OK for mainline / 10? Thanks, Harald PR fortran/99205 - Out of memory with undefined character length A character variable appearing as a data statement object cannot be automatic, thus it shall have constant length. gcc/fortran/ChangeLog: PR fortran/99205 * data.c (gfc_assign_data_value): Reject non-constant character length for lvalue. * trans-array.c (gfc_conv_array_initializer): Restrict loop to elements which are defined to avoid NULL pointer dereference. gcc/testsuite/ChangeLog: PR fortran/99205 * gfortran.dg/data_char_4.f90: New test. * gfortran.dg/data_char_5.f90: New test. --sgnirk-4aa5439d-d9f4-40b1-989e-4730c4675d2a Content-Type: application/octet-stream Content-Disposition: attachment; filename=pr99205.patch-v2 Content-Transfer-Encoding: quoted-printable diff --git a/gcc/fortran/data.c b/gcc/fortran/data.c index 25e97930169..71e2552025d 100644 =2D-- a/gcc/fortran/data.c +++ b/gcc/fortran/data.c @@ -595,6 +595,9 @@ gfc_assign_data_value (gfc_expr *lvalue, gfc_expr *rva= lue, mpz_t index, /* An initializer has to be constant. */ if (lvalue->ts.u.cl->length =3D=3D NULL && !(ref && ref->u.ss.lengt= h !=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/fortran/trans-array.c b/gcc/fortran/trans-array.c index c6725659093..478cddda070 100644 =2D-- a/gcc/fortran/trans-array.c +++ b/gcc/fortran/trans-array.c @@ -6162,7 +6162,7 @@ gfc_conv_array_initializer (tree type, gfc_expr * ex= pr) case EXPR_ARRAY: /* Create a vector of all the elements. */ for (c =3D gfc_constructor_first (expr->value.constructor); - c; c =3D gfc_constructor_next (c)) + c && c->expr; c =3D gfc_constructor_next (c)) { if (c->iterator) { diff --git a/gcc/testsuite/gfortran.dg/data_char_4.f90 b/gcc/testsuite/gfo= rtran.dg/data_char_4.f90 new file mode 100644 index 00000000000..ed0782ce8a0 =2D-- /dev/null +++ b/gcc/testsuite/gfortran.dg/data_char_4.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 = } diff --git a/gcc/testsuite/gfortran.dg/data_char_5.f90 b/gcc/testsuite/gfo= rtran.dg/data_char_5.f90 new file mode 100644 index 00000000000..ea26687e3d5 =2D-- /dev/null +++ b/gcc/testsuite/gfortran.dg/data_char_5.f90 @@ -0,0 +1,15 @@ +! { dg-do compile } +! PR fortran/99205 - Issues with non-constant character length + +subroutine sub () + integer :: ll =3D 4 + block + character(ll) :: c(2) ! { dg-error "non-constant" } + data c /'a', 'b'/ + end block +contains + subroutine sub1 () + character(ll) :: d(2) ! { dg-error "non-constant" } + data d /'a', 'b'/ + end subroutine sub1 +end subroutine sub --sgnirk-4aa5439d-d9f4-40b1-989e-4730c4675d2a--