public inbox for fortran@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] PR fortran/103778 - [10/11/12 Regression] ICE: Invalid expression in gfc_element_size
@ 2021-12-20 21:18 Harald Anlauf
  0 siblings, 0 replies; only message in thread
From: Harald Anlauf @ 2021-12-20 21:18 UTC (permalink / raw)
  To: fortran, gcc-patches

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

Dear all,

again found by Gerhard: using a BOZ literal constant in situations
where an interoperable object is expected can lead to an ICE.
But obviously a BOZ in not interoperable.

Obvious patch, regtested on x86_64-pc-linux-gnu.

Will commit within 48h unless there are objections or better
suggestions.

Thanks,
Harald


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Fortran-BOZ-literal-constants-are-not-interoperable.patch --]
[-- Type: text/x-patch, Size: 1614 bytes --]

From 2e6c83fbddda3215faf111263ebfc754bc07096c Mon Sep 17 00:00:00 2001
From: Harald Anlauf <anlauf@gmx.de>
Date: Mon, 20 Dec 2021 22:12:33 +0100
Subject: [PATCH] Fortran: BOZ literal constants are not interoperable

gcc/fortran/ChangeLog:

	PR fortran/103778
	* check.c (is_c_interoperable): A BOZ literal constant is not
	interoperable.

gcc/testsuite/ChangeLog:

	PR fortran/103778
	* gfortran.dg/illegal_boz_arg_3.f90: New test.
---
 gcc/fortran/check.c                             | 6 ++++++
 gcc/testsuite/gfortran.dg/illegal_boz_arg_3.f90 | 7 +++++++
 2 files changed, 13 insertions(+)
 create mode 100644 gcc/testsuite/gfortran.dg/illegal_boz_arg_3.f90

diff --git a/gcc/fortran/check.c b/gcc/fortran/check.c
index 625473c90d1..b4db9337e9f 100644
--- a/gcc/fortran/check.c
+++ b/gcc/fortran/check.c
@@ -5185,6 +5185,12 @@ is_c_interoperable (gfc_expr *expr, const char **msg, bool c_loc, bool c_f_ptr)
       return false;
     }

+  if (expr->ts.type == BT_BOZ)
+    {
+      *msg = "BOZ literal constant";
+      return false;
+    }
+
   if (expr->ts.type == BT_CLASS)
     {
       *msg = "Expression is polymorphic";
diff --git a/gcc/testsuite/gfortran.dg/illegal_boz_arg_3.f90 b/gcc/testsuite/gfortran.dg/illegal_boz_arg_3.f90
new file mode 100644
index 00000000000..59fefa90971
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/illegal_boz_arg_3.f90
@@ -0,0 +1,7 @@
+! { dg-do compile }
+! PR fortran/103778
+
+program p
+  use iso_c_binding, only : c_sizeof
+  integer, parameter :: a = c_sizeof(z'1') ! { dg-error "cannot appear" }
+end
--
2.26.2


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2021-12-20 21:18 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-12-20 21:18 [PATCH] PR fortran/103778 - [10/11/12 Regression] ICE: Invalid expression in gfc_element_size Harald Anlauf

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).