From: Harald Anlauf <anlauf@gmx.de>
To: Tobias Burnus <tobias@codesourcery.com>
Cc: fortran <fortran@gcc.gnu.org>, gcc-patches <gcc-patches@gcc.gnu.org>
Subject: Re: [PATCH] PR fortran/99205 - [10/11 Regression] Out of memory with undefined character length
Date: Wed, 10 Mar 2021 22:26:38 +0100 [thread overview]
Message-ID: <trinity-97446242-7777-4065-a9f8-cf10c968255f-1615411598627@3c-app-gmx-bs58> (raw)
In-Reply-To: <8a63eb89-91e6-1e8d-870e-8a2f7a6750df@codesourcery.com>
[-- Attachment #1: Type: text/plain, Size: 1730 bytes --]
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.
[-- Attachment #2: pr99205.patch-v2 --]
[-- Type: application/octet-stream, Size: 2351 bytes --]
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 *rvalue, mpz_t index,
/* An initializer has to be constant. */
if (lvalue->ts.u.cl->length == NULL && !(ref && ref->u.ss.length != NULL))
return false;
+ if (lvalue->ts.u.cl->length
+ && lvalue->ts.u.cl->length->expr_type != EXPR_CONSTANT)
+ return false;
expr = 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
--- a/gcc/fortran/trans-array.c
+++ b/gcc/fortran/trans-array.c
@@ -6162,7 +6162,7 @@ gfc_conv_array_initializer (tree type, gfc_expr * expr)
case EXPR_ARRAY:
/* Create a vector of all the elements. */
for (c = gfc_constructor_first (expr->value.constructor);
- c; c = gfc_constructor_next (c))
+ c && c->expr; c = gfc_constructor_next (c))
{
if (c->iterator)
{
diff --git a/gcc/testsuite/gfortran.dg/data_char_4.f90 b/gcc/testsuite/gfortran.dg/data_char_4.f90
new file mode 100644
index 00000000000..ed0782ce8a0
--- /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/gfortran.dg/data_char_5.f90
new file mode 100644
index 00000000000..ea26687e3d5
--- /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 = 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
next prev parent reply other threads:[~2021-03-10 21:26 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-03-09 19:45 Harald Anlauf
2021-03-10 10:06 ` Tobias Burnus
2021-03-10 19:43 ` Harald Anlauf
2021-03-10 20:18 ` Tobias Burnus
2021-03-10 21:26 ` Harald Anlauf [this message]
2021-03-10 21:52 ` Tobias Burnus
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=trinity-97446242-7777-4065-a9f8-cf10c968255f-1615411598627@3c-app-gmx-bs58 \
--to=anlauf@gmx.de \
--cc=fortran@gcc.gnu.org \
--cc=gcc-patches@gcc.gnu.org \
--cc=tobias@codesourcery.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).