public inbox for fortran@gcc.gnu.org
 help / color / mirror / Atom feed
From: Harald Anlauf <anlauf@gmx.de>
To: fortran <fortran@gcc.gnu.org>, gcc-patches <gcc-patches@gcc.gnu.org>
Subject: [PATCH] PR fortran/99205 - [10/11 Regression] Out of memory with undefined character length
Date: Tue, 9 Mar 2021 20:45:00 +0100	[thread overview]
Message-ID: <trinity-f0b06340-8653-42d5-b5bf-fcfb5e2ce01e-1615319100120@3c-app-gmx-bs50> (raw)

[-- Attachment #1: Type: text/plain, Size: 604 bytes --]

Dear all,

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?

Thanks,
Harald


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.

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.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: pr99205.patch --]
[-- Type: text/x-patch, Size: 1165 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/testsuite/gfortran.dg/pr99205.f90 b/gcc/testsuite/gfortran.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 }

             reply	other threads:[~2021-03-09 19:45 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-09 19:45 Harald Anlauf [this message]
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
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-f0b06340-8653-42d5-b5bf-fcfb5e2ce01e-1615319100120@3c-app-gmx-bs50 \
    --to=anlauf@gmx.de \
    --cc=fortran@gcc.gnu.org \
    --cc=gcc-patches@gcc.gnu.org \
    /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).