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] Fortran: BOZ literal constants are not compatible to any type [PR103413]
Date: Wed, 26 Oct 2022 21:15:38 +0200	[thread overview]
Message-ID: <trinity-a8c1203c-bd17-4bfc-85c9-854076a1c363-1666811738919@3c-app-gmx-bap72> (raw)

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

Dear all,

a BOZ as source-expression in an ALLOCATE statement could lead
to an ICE when the allocate-object was a CLASS variable.
Since a BOZ has no type, we can handle it as type incompatible
with any type.  This is also what the Cray compiler does for
the code in the testcase.

Regtested on x86_64-pc-linux-gnu.  OK for mainline?

The PR is marked as a 10/11/12/13 regression, so OK for backports?

Thanks,
Harald


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: pr103413.diff --]
[-- Type: text/x-patch, Size: 1914 bytes --]

From 986bf9cc5abc51598609b16edc9242a87244571b Mon Sep 17 00:00:00 2001
From: Harald Anlauf <anlauf@gmx.de>
Date: Wed, 26 Oct 2022 21:00:44 +0200
Subject: [PATCH] Fortran: BOZ literal constants are not compatible to any type
 [PR103413]

gcc/fortran/ChangeLog:

	PR fortran/103413
	* symbol.cc (gfc_type_compatible): A boz-literal-constant has no type
	and thus is not considered compatible to any type.

gcc/testsuite/ChangeLog:

	PR fortran/103413
	* gfortran.dg/illegal_boz_arg_4.f90: New test.
---
 gcc/fortran/symbol.cc                           |  4 ++++
 gcc/testsuite/gfortran.dg/illegal_boz_arg_4.f90 | 13 +++++++++++++
 2 files changed, 17 insertions(+)
 create mode 100644 gcc/testsuite/gfortran.dg/illegal_boz_arg_4.f90

diff --git a/gcc/fortran/symbol.cc b/gcc/fortran/symbol.cc
index 6050359d521..49fb37864bd 100644
--- a/gcc/fortran/symbol.cc
+++ b/gcc/fortran/symbol.cc
@@ -5139,6 +5139,10 @@ gfc_type_compatible (gfc_typespec *ts1, gfc_typespec *ts2)
   bool is_union1 = (ts1->type == BT_UNION);
   bool is_union2 = (ts2->type == BT_UNION);

+  /* A boz-literal-constant has no type.  */
+  if (ts1->type == BT_BOZ || ts2->type == BT_BOZ)
+    return false;
+
   if (is_class1
       && ts1->u.derived->components
       && ((ts1->u.derived->attr.is_class
diff --git a/gcc/testsuite/gfortran.dg/illegal_boz_arg_4.f90 b/gcc/testsuite/gfortran.dg/illegal_boz_arg_4.f90
new file mode 100644
index 00000000000..856cfa9211f
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/illegal_boz_arg_4.f90
@@ -0,0 +1,13 @@
+! { dg-do compile }
+! { dg-options "-std=f2018" }
+! PR fortran/103413
+! Contributed by G.Steinmetz
+
+program p
+  type t
+     class(*), allocatable :: a
+  end type
+  type(t) :: x
+  allocate (x%a, source=z'1') ! { dg-error "type incompatible" }
+  allocate (x%a, mold=z'1')   ! { dg-error "type incompatible" }
+end
--
2.35.3


             reply	other threads:[~2022-10-26 19:15 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-10-26 19:15 Harald Anlauf [this message]
2022-10-26 20:08 ` Mikael Morin

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-a8c1203c-bd17-4bfc-85c9-854076a1c363-1666811738919@3c-app-gmx-bap72 \
    --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).