Dear Fortranners,
when debugging the testcase, I noticed that a coarray declaration in
a COMMON statement wrongly set the dimension attribute instead of the
codimension. As a consequence, subsequent checks that catch this
invalid situation would not trigger.
I see two possible solutions:
- in gfc_match_common, replace
/* Deal with an optional array specification after the
symbol name. */
m = gfc_match_array_spec (&as, true, true);
by
m = gfc_match_array_spec (&as, true, false);
which in turn would lead to a syntax error. Interestingly, the Intel
compiler also takes this route and gives a syntax error.
- check the resulting as->corank and emit an error as in the attached
patch.
The attached patch regtests fine on x86_64-pc-linux-gnu. OK for mainline?
Thanks,
Harald
Fortran: a symbol in a COMMON cannot be a coarray
gcc/fortran/ChangeLog:
PR fortran/69419
* match.c (gfc_match_common): Check array spec of a symbol in a
COMMON object list and reject it if it is a coarray.
gcc/testsuite/ChangeLog:
PR fortran/69419
* gfortran.dg/pr69419.f90: New test.
diff --git a/gcc/fortran/match.c b/gcc/fortran/match.c
index 53a575e616e..df97620634d 100644
--- a/gcc/fortran/match.c
+++ b/gcc/fortran/match.c
@@ -5314,6 +5314,13 @@ gfc_match_common (void)
goto cleanup;
}
+ if (as->corank)
+ {
+ gfc_error ("Symbol %qs in COMMON at %C cannot be a "
+ "coarray", sym->name);
+ goto cleanup;
+ }
+
if (!gfc_add_dimension (&sym->attr, sym->name, NULL))
goto cleanup;
diff --git a/gcc/testsuite/gfortran.dg/pr69419.f90 b/gcc/testsuite/gfortran.dg/pr69419.f90
new file mode 100644
index 00000000000..7329808611c
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/pr69419.f90
@@ -0,0 +1,9 @@
+! { dg-do compile }
+! { dg-options "-fcoarray=lib" }
+! PR fortran/69419 - ICE on invalid coarray in common
+
+blockdata b
+ real x ! { dg-error "must be in COMMON" }
+ common /c/ x[*] ! { dg-error "cannot be a coarray" }
+ data x /1.0/
+end