[v2] Fortran: diagnose strings of non-constant length in DATA statements [PR68569]
Checks
Commit Message
Dear all,
the original submission missed the adjustments of the expected
patterns of 2 tests. This is corrected in the new attachments.
Am 26.07.23 um 21:10 schrieb Harald Anlauf via Gcc-patches:
> Dear all,
>
> the attached patch fixes an ICE-on-invalid after use of strings of
> non-constant length in DATA statements.
>
> Regtested on x86_64-pc-linux-gnu. OK for mainline?
>
> Thanks,
> Harald
>
Thanks,
Harald
@@ -16771,7 +16787,6 @@ check_data_variable (gfc_data_variable *var, locus *where)
return false;
ar = NULL;
- mpz_init_set_si (offset, 0);
e = var->expr;
if (e->expr_type == EXPR_FUNCTION && e->value.function.isym
@@ -16838,8 +16853,24 @@ check_data_variable (gfc_data_variable *var, locus *where)
"attribute", ref->u.c.component->name, &e->where);
return false;
}
+
+ /* Reject substrings of strings of non-constant length. */
+ if (ref->type == REF_SUBSTRING
+ && ref->u.ss.length
+ && ref->u.ss.length->length
+ && !gfc_is_constant_expr (ref->u.ss.length->length))
+ goto bad_charlen;
}
+ /* Reject deferred length character and strings of non-constant length. */
+ if (e->ts.type == BT_CHARACTER
+ && (e->ts.deferred
+ || (e->ts.u.cl->length
+ && !gfc_is_constant_expr (e->ts.u.cl->length))))
+ goto bad_charlen;
+
+ mpz_init_set_si (offset, 0);
+
if (e->rank == 0 || has_pointer)
{
mpz_init_set_ui (size, 1);
@@ -16967,6 +16998,11 @@ check_data_variable (gfc_data_variable *var, locus *where)
mpz_clear (offset);
return t;
+
+bad_charlen:
+ gfc_error ("Non-constant character length at %L in DATA statement",
+ &e->where);
+ return false;
}