diff mbox

[fortran,04/21] Remove coarray support in the scalarizer: Fix gfc_get_corank

Message ID 20110915230822.28513.77343@gimli.local
State New
Headers show

Commit Message

Mikael Morin Sept. 15, 2011, 11:08 p.m. UTC
This patch was necessary on a previous version of the patchset (I was calling
gfc_get_corank on non-coarrays with e->symtree == NULL, and it was segfaulting
on the first e->symtree dereferencing). In the current version, it is optional,
but I propose it anyway as (I think) it makes some sense. 

The patch itself doesn't need extra explanations.
We could add an early return dealing with non-coarray cases (this is the variant
proposed), an assertion that input is really a coarray, or nothing at all.
Either works. Which one is best?
2011-09-14  Morin  <mikael.morin@sfr.fr>

	* expr.c (gfc_get_corank): Return 0 if input expression is not a
	coarray.
diff mbox

Patch

diff --git a/expr.c b/expr.c
index 3c09a2a..056da71 100644
--- a/expr.c
+++ b/expr.c
@@ -4293,13 +4293,19 @@  gfc_get_corank (gfc_expr *e)
 {
   int corank;
   gfc_ref *ref;
+
+  if (!gfc_is_coarray (e))
+    return 0;
+
   corank = e->symtree->n.sym->as ? e->symtree->n.sym->as->corank : 0;
+
   for (ref = e->ref; ref; ref = ref->next)
     {
       if (ref->type == REF_ARRAY)
 	corank = ref->u.ar.as->corank;
       gcc_assert (ref->type != REF_SUBSTRING);
     }
+
   return corank;
 }