Dear all,
the present PR has two issues. The first one, addressed by this patch,
was about accepting invalid code where a variable appeared both in a
declaration with PARAMETER as well as in a DATA statement, which could
lead to an ICE. We now reject this.
(There is a separate issue about combining default initialization with
DATA leading to a wrong constructor and thus wrong code. I'd prefer to
have this addressed separately.)
Regtested on x86_64-pc-linux-gnu. OK for mainline?
Thanks,
Harald
PR fortran/49278 - ICE when combining DATA with default initialization
A variable with the PARAMETER attribute may not appear in a DATA statement.
gcc/fortran/ChangeLog:
PR fortran/49278
* data.c (gfc_assign_data_value): Reject variable with PARAMETER
attribute in DATA statement.
gcc/testsuite/ChangeLog:
PR fortran/49278
* gfortran.dg/parameter_data.f90: New test.
diff --git a/gcc/fortran/data.c b/gcc/fortran/data.c
index 13e3506dd1e..25e97930169 100644
--- a/gcc/fortran/data.c
+++ b/gcc/fortran/data.c
@@ -244,6 +244,13 @@ gfc_assign_data_value (gfc_expr *lvalue, gfc_expr *rvalue, mpz_t index,
"array-element nor a scalar-structure-component";
symbol = lvalue->symtree->n.sym;
+ if (symbol->attr.flavor == FL_PARAMETER)
+ {
+ gfc_error ("PARAMETER %qs shall not appear in a DATA statement at %L",
+ symbol->name, &lvalue->where);
+ return false;
+ }
+
init = symbol->value;
last_ts = &symbol->ts;
last_con = NULL;
diff --git a/gcc/testsuite/gfortran.dg/parameter_data.f90 b/gcc/testsuite/gfortran.dg/parameter_data.f90
new file mode 100644
index 00000000000..b95f9c90696
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/parameter_data.f90
@@ -0,0 +1,13 @@
+! { dg-do compile }
+! PR fortran/49278 - ICE when combining DATA with default initialization
+
+program p
+ implicit none
+ type t
+ real :: a
+ end type t
+ integer, parameter :: b = 42
+ type(t), parameter :: z = t(4.0)
+ data b / 666 / ! { dg-error "shall not appear in a DATA statement" }
+ data z%a / 3.0 / ! { dg-error "shall not appear in a DATA statement" }
+end