diff mbox series

[fortran] PR107397 ICE in gfc_arith_plus, at fortran/arith.cc:654

Message ID 5dac7c39-c0e3-f7e7-8625-b672fc728e0c@gmail.com
State New
Headers show
Series [fortran] PR107397 ICE in gfc_arith_plus, at fortran/arith.cc:654 | expand

Commit Message

Jerry D Dec. 17, 2022, 5:12 p.m. UTC
Hi all,

The attached patch fixes a regression and is a patch from Steve.  I have 
regression tested it and provided a test case.  It is fairly simple and 
I will commit under the "simple" rule in a little while.

Thanks Steve for Patch. Thanks Harald for helping me get back up to 
speed on the git magic.

Regards,

Jerry
diff mbox series

Patch

diff --git a/gcc/fortran/decl.cc b/gcc/fortran/decl.cc
index 0f9b2ced4c2..1562dc22bc6 100644
--- a/gcc/fortran/decl.cc
+++ b/gcc/fortran/decl.cc
@@ -2221,6 +2221,14 @@  add_init_expr_to_sym (const char *name, gfc_expr **initp, locus *var_locus)
 	    sym->ts.f90_type = init->ts.f90_type;
 	}
 
+      /* Catch the case:  type(t), parameter :: x = z'1'.  */
+      if (sym->ts.type == BT_DERIVED && init->ts.type == BT_BOZ)
+	{
+	  gfc_error ("Entity %qs at %L is incompatible with a BOZ "
+		     "literal constant", name, &sym->declared_at);
+	  return false;
+	}
+
       /* Add initializer.  Make sure we keep the ranks sane.  */
       if (sym->attr.dimension && init->rank == 0)
 	{
diff --git a/gcc/testsuite/gfortran.dg/pr107397.f90 b/gcc/testsuite/gfortran.dg/pr107397.f90
new file mode 100644
index 00000000000..4592a275e70
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/pr107397.f90
@@ -0,0 +1,9 @@ 
+!{ dg-do compile }
+!
+program p
+  type t
+    real :: a = 1.0
+  end type
+  type(t), parameter :: x = z'1' ! { dg-error "incompatible with BOZ" }
+  x%a = x%a + 2 ! { dg-error "has no IMPLICIT type"}
+end