This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[Committed] PR fortran/92174
- From: Steve Kargl <sgk at troutmask dot apl dot washington dot edu>
- To: fortran at gcc dot gnu dot org, gcc-patches at gcc dot gnu dot org
- Date: Tue, 22 Oct 2019 11:24:27 -0700
- Subject: [Committed] PR fortran/92174
- Reply-to: sgk at troutmask dot apl dot washington dot edu
Committed as not so-obvious as I don't use UBSAN when fixing bugs.
The patch pushes the F2018:C822 check down a layer to prevent a segfault
when UBSAN is used.
2019-10-22 Steven G. Kargl <kargl@gcc.gnu.org>
PR fortran/92174
* decl.c (attr_decl1): Move check for F2018:C822 from here ...
* array.c (gfc_set_array_spec): ... to here.
--
Steve
Index: gcc/fortran/array.c
===================================================================
--- gcc/fortran/array.c (revision 277262)
+++ gcc/fortran/array.c (working copy)
@@ -862,6 +863,10 @@ gfc_set_array_spec (gfc_symbol *sym, gfc_array_spec *a
sym->as->cotype = as->cotype;
sym->as->corank = as->corank;
+ /* Check F2018:C822. */
+ if (sym->as->rank + sym->as->corank > GFC_MAX_DIMENSIONS)
+ goto too_many;
+
for (i = 0; i < as->corank; i++)
{
sym->as->lower[sym->as->rank + i] = as->lower[i];
@@ -880,6 +885,10 @@ gfc_set_array_spec (gfc_symbol *sym, gfc_array_spec *a
sym->as->cray_pointee = as->cray_pointee;
sym->as->cp_was_assumed = as->cp_was_assumed;
+ /* Check F2018:C822. */
+ if (sym->as->rank + sym->as->corank > GFC_MAX_DIMENSIONS)
+ goto too_many;
+
for (i = 0; i < sym->as->corank; i++)
{
sym->as->lower[as->rank + i] = sym->as->lower[i];
@@ -894,6 +903,12 @@ gfc_set_array_spec (gfc_symbol *sym, gfc_array_spec *a
free (as);
return true;
+
+too_many:
+
+ gfc_error ("rank + corank of %qs exceeds %d at %C", sym->name,
+ GFC_MAX_DIMENSIONS);
+ return false;
}
Index: gcc/fortran/decl.c
===================================================================
--- gcc/fortran/decl.c (revision 277262)
+++ gcc/fortran/decl.c (working copy)
@@ -8524,15 +8524,6 @@ attr_decl1 (void)
goto cleanup;
}
- /* Check F2018:C822. */
- if (sym->attr.dimension && sym->attr.codimension
- && sym->as && sym->as->rank + sym->as->corank > 15)
- {
- gfc_error ("rank + corank of %qs exceeds 15 at %C", sym->name);
- m = MATCH_ERROR;
- return m;
- }
-
if (sym->attr.cray_pointee && sym->as != NULL)
{
/* Fix the array spec. */