------- Comment #3 from paul dot thomas at jet dot uk  2006-05-05 06:26 -------
The patch below fixes the problem by enclosing the expression for the array
reference outputs%signal_number in parentheses(You can verify that this does
the right thing by doing it explicitly in the fortran.).  This turns the
temporary, used in the scalarizer loop, from the structure into its integer
component, signal_number.  I did contemplate doing clever stuff with tree_ssa,
a bit further down stream, but this is much simpler and works.

I will do all the good things with assigning this PR to myself and submitting
the patch, when I am back at base.

Richard, which email address do you prefer in the attribution to you, in the
testscase?

Paul

Index: gcc/fortran/matchexp.c
===================================================================
--- gcc/fortran/matchexp.c      (révision 113499)
+++ gcc/fortran/matchexp.c      (copie de travail)
@@ -123,6 +123,26 @@
 }


+/* Call the INTRINSIC_PARENTHESES function.  This is both
+   used explicitly, as below, or by resolve.c to generate
+   temporaries.  */
+gfc_expr *
+gfc_get_parentheses (gfc_expr *e)
+{
+  gfc_expr *e2;
+
+  e2 = gfc_get_expr();
+  e2->expr_type = EXPR_OP;
+  e2->ts = e->ts;
+  e2->rank = e->rank;
+  e2->where = e->where;
+  e2->value.op.operator = INTRINSIC_PARENTHESES;
+  e2->value.op.op1 = e;
+  e2->value.op.op2 = NULL;
+  return e2;
+}
+
+
 /* Match a primary expression.  */

 static match
@@ -167,19 +187,8 @@
   if(!gfc_numeric_ts(&e->ts))
     *result = e;
   else
-    {
-      gfc_expr *e2 = gfc_get_expr();
+    *result = gfc_get_parentheses (e);

-      e2->expr_type = EXPR_OP;
-      e2->ts = e->ts;
-      e2->rank = e->rank;
-      e2->where = where;
-      e2->value.op.operator = INTRINSIC_PARENTHESES;
-      e2->value.op.op1 = e;
-      e2->value.op.op2 = NULL;
-      *result = e2;
-    }
-
   if (m != MATCH_YES)
     {
       gfc_free_expr (*result);
Index: gcc/fortran/gfortran.h
===================================================================
--- gcc/fortran/gfortran.h      (révision 113499)
+++ gcc/fortran/gfortran.h      (copie de travail)
@@ -1940,6 +1940,9 @@
 void gfc_free_data (gfc_data *);
 void gfc_free_case_list (gfc_case *);

+/* matchexp.c -- FIXME too?  */
+gfc_expr *gfc_get_parentheses (gfc_expr *);
+
 /* openmp.c */
 void gfc_free_omp_clauses (gfc_omp_clauses *);
 void gfc_resolve_omp_directive (gfc_code *, gfc_namespace *);
Index: gcc/fortran/resolve.c
===================================================================
--- gcc/fortran/resolve.c       (révision 113499)
+++ gcc/fortran/resolve.c       (copie de travail)
@@ -2284,6 +2284,7 @@
 resolve_array_ref (gfc_array_ref * ar)
 {
   int i, check_scalar;
+  gfc_expr *e;

   for (i = 0; i < ar->dimen; i++)
     {
@@ -2295,9 +2296,11 @@
        return FAILURE;
       if (gfc_resolve_index (ar->stride[i], check_scalar) == FAILURE)
        return FAILURE;
+      
+      e = ar->start[i];

       if (ar->dimen_type[i] == DIMEN_UNKNOWN)
-       switch (ar->start[i]->rank)
+       switch (e->rank)
          {
          case 0:
            ar->dimen_type[i] = DIMEN_ELEMENT;
@@ -2305,11 +2308,15 @@

          case 1:
            ar->dimen_type[i] = DIMEN_VECTOR;
+           if (e->expr_type == EXPR_VARIABLE
+                 && e->symtree->n.sym->ts.type == BT_DERIVED)
+             ar->start[i] = gfc_get_parentheses (e);
+           
            break;

          default:
            gfc_error ("Array index at %L is an array of rank %d",
-                      &ar->c_where[i], ar->start[i]->rank);
+                      &ar->c_where[i], e->rank);
            return FAILURE;
          }
     }
@@ -4363,6 +4370,7 @@
                             &code->loc);
                  break;
                }
+
              goto call;
            }



-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=27411

Reply via email to