This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug fortran/31258] segfault with transpose(reshape(char))



------- Comment #2 from pault at gcc dot gnu dot org  2007-04-08 09:40 -------
This fixes this PR and PR31197.  It needs some work because it still fails with
variable expressions in the string length and I need to figure out which other
intrinsics, if any, need the same treatment.

Paul

Index: /svn/trunk/gcc/fortran/iresolve.c
===================================================================
*** /svn/trunk/gcc/fortran/iresolve.c   (revision 123646)
--- /svn/trunk/gcc/fortran/iresolve.c   (working copy)
*************** gfc_resolve_reshape (gfc_expr *f, gfc_ex
*** 1722,1727 ****
--- 1722,1755 ----
        break;
      }

+   if (source->ts.type == BT_CHARACTER
+       && source->ref != NULL)
+     {
+       gfc_ref *ref;
+       for (ref = source->ref; ref; ref = ref->next)
+       if (ref->next == NULL && ref->type == REF_SUBSTRING)
+         break;
+       if (ref != NULL)
+       {
+         f->ts.type = BT_CHARACTER;
+         f->ts.kind = gfc_default_character_kind;
+         f->ts.cl = gfc_get_charlen ();
+         f->ts.cl->next = gfc_current_ns->cl_list;
+         gfc_current_ns->cl_list = f->ts.cl;
+         f->ts.cl->length = gfc_get_expr ();
+         f->ts.cl->length->expr_type = EXPR_OP;
+         f->ts.cl->length->value.op.operator = INTRINSIC_PLUS;
+         f->ts.cl->length->value.op.op1 = gfc_get_expr ();
+         f->ts.cl->length->value.op.op1->expr_type = EXPR_OP;
+         f->ts.cl->length->value.op.op1->value.op.operator = INTRINSIC_MINUS;
+         f->ts.cl->length->value.op.op1->value.op.op1 = gfc_copy_expr
(ref->u.ss.end);
+         f->ts.cl->length->value.op.op1->value.op.op2 = gfc_copy_expr
(ref->u.ss.start);
+
+         f->ts.cl->length->value.op.op2 =  gfc_int_expr (1);
+         gfc_simplify_expr (f->ts.cl->length, 0);
+       }
+     }
+
    /* TODO: Make this work with a constant ORDER parameter.  */
    if (shape->expr_type == EXPR_ARRAY
        && gfc_is_constant_expr (shape)


-- 


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]