[gfortran] PR 15327: Fix merge intrinsic for strings

Tobias Schlüter tobias.schlueter@physik.uni-muenchen.de
Wed Sep 1 22:38:00 GMT 2004


Paul Brook wrote:
> merge (a, b, flag) should expand to
> _result = flag?a:b; _result_length = len(a)
> ie. basically the same as the numeric case, but also setting the string 
> length.

Done. Updated patch below. Yes, this is much better.

Built and tested. OK?

- Tobi

2004-09-01  Tobias Schlueter  <tobias.schlueter@physik.uni-muenchen.de>

	PR fortran/15327
	* trans-intrinsic.c (gfc_conv_intrinsic_merge): Do the right thing for
	strings.

Index: trans-intrinsic.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/fortran/trans-intrinsic.c,v
retrieving revision 1.20
diff -c -3 -p -r1.20 trans-intrinsic.c
*** trans-intrinsic.c   30 Aug 2004 21:59:07 -0000      1.20
--- trans-intrinsic.c   1 Sep 2004 22:33:28 -0000
*************** gfc_conv_intrinsic_merge (gfc_se * se, g
*** 1998,2013 ****
    tree fsource;
    tree mask;
    tree type;

    arg = gfc_conv_intrinsic_function_args (se, expr);
!   tsource = TREE_VALUE (arg);
!   arg = TREE_CHAIN (arg);
!   fsource = TREE_VALUE (arg);
!   arg = TREE_CHAIN (arg);
!   mask = TREE_VALUE (arg);

!   type = TREE_TYPE (tsource);
!   se->expr = fold (build3 (COND_EXPR, type, mask, tsource, fsource));
  }


--- 1998,2033 ----
    tree fsource;
    tree mask;
    tree type;
+   tree len;

    arg = gfc_conv_intrinsic_function_args (se, expr);
!   if (expr->ts.type != BT_CHARACTER)
!     {
!       tsource = TREE_VALUE (arg);
!       arg = TREE_CHAIN (arg);
!       fsource = TREE_VALUE (arg);
!       arg = TREE_CHAIN (arg);
!       mask = TREE_VALUE (arg);
!       type = TREE_TYPE (tsource);
!       se->expr = fold (build3 (COND_EXPR, type, mask, tsource, fsource));
!     }
!   else
!     {
!       /* We do the same as in the non-character case, but the argument
!        list is different because of the string length arguments. We
!        also have to set the string length for the result.  */
!       len = TREE_VALUE (arg);
!       arg = TREE_CHAIN (arg);
!       tsource = TREE_VALUE (arg);
!       arg = TREE_CHAIN (TREE_CHAIN (arg));
!       fsource = TREE_VALUE (arg);
!       mask = TREE_VALUE (TREE_CHAIN (arg));
!
!       type = TREE_TYPE (tsource);

!       se->string_length = len;
!       se->expr = fold (build3 (COND_EXPR, type, mask, tsource, fsource));
!     }
  }






More information about the Gcc-patches mailing list