aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSteven G. Kargl <kargl@gcc.gnu.org>2020-03-05 11:41:14 +0000
committerMark Eggleston <markeggleston@gcc.gnu.org>2020-03-05 11:41:14 +0000
commita2ec7c4aafbcd517eb563f1df32eedf39b27141b (patch)
tree861470c13c40f2394d6d9233b88b33cd18a3e664
parent43031fbdda7d4edbd607365a4f3bbec069fe3983 (diff)
Fortran: ICE in gfc_code2string PR93792
A BOZ constant can not appear as a component inialiser for a derived type. gcc/fortran/ChangeLog: PR93792 * decl.c (variable_decl): If param and initializer check for BOZ, if found, output an error, set m to MATCH_ERROR and goto cleanup. gcc/testsuite/ChangeLog: PR93792 * gfortran.dg/pr93792.f90: New test.
-rw-r--r--gcc/fortran/ChangeLog7
-rw-r--r--gcc/fortran/decl.c11
-rw-r--r--gcc/testsuite/ChangeLog5
-rw-r--r--gcc/testsuite/gfortran.dg/pr93792.f9017
4 files changed, 39 insertions, 1 deletions
diff --git a/gcc/fortran/ChangeLog b/gcc/fortran/ChangeLog
index e3957fbac4d..90e1cabbe20 100644
--- a/gcc/fortran/ChangeLog
+++ b/gcc/fortran/ChangeLog
@@ -1,3 +1,10 @@
+2020-03-05 Steven G. Kargl <kargl@gcc.gnu.org>
+
+ PR fortran/93792
+ * decl.c (variable_decl): If param and initializer check
+ for BOZ, if found, output an error, set m to MATCH_ERROR
+ and goto cleanup.
+
2020-03-02 Andrew Benson <abensonca@gmail.com>
PR fortran/93486
diff --git a/gcc/fortran/decl.c b/gcc/fortran/decl.c
index 7382fea03e4..2f458c4faac 100644
--- a/gcc/fortran/decl.c
+++ b/gcc/fortran/decl.c
@@ -2929,7 +2929,16 @@ variable_decl (int elem)
goto cleanup;
}
else if (param && initializer)
- param->value = gfc_copy_expr (initializer);
+ {
+ if (initializer->ts.type == BT_BOZ)
+ {
+ gfc_error ("BOZ literal constant at %L cannot appear as an "
+ "initializer", &initializer->where);
+ m = MATCH_ERROR;
+ goto cleanup;
+ }
+ param->value = gfc_copy_expr (initializer);
+ }
}
/* Before adding a possible initilizer, do a simple check for compatibility
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 7dcc80d0851..851e0e92807 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,8 @@
+2020-03-05 Mark Eggleston <mark.eggleston@codethink.com>
+
+ PR fortran/93792
+ * gfortran.dg/pr93792.f90: New test.
+
2020-03-05 Delia Burduv <delia.burduv@arm.com>
* gcc.target/arm/simd/bf16_ma_1.c: New test.
diff --git a/gcc/testsuite/gfortran.dg/pr93792.f90 b/gcc/testsuite/gfortran.dg/pr93792.f90
new file mode 100644
index 00000000000..960d05025ab
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/pr93792.f90
@@ -0,0 +1,17 @@
+! { dg-do compile }
+! Original test case by Gernhard Steinmetz.
+
+module m
+ type t(n)
+ integer, len :: n = z'1'
+ end type
+end
+program p
+ use m
+ type(t(:)), allocatable :: z
+end
+
+! { dg-error "Parameterized type 't' does not have a component" " " { target *-*-* } 5 }
+! { dg-error "BOZ literal constant at .1. cannot appear" " " { target *-*-* } 6 }
+! { dg-error "Cannot open module file" " " { target *-*-* } 10 }
+! { dg-excess-errors "compilation terminated" }