This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [gfortran] PR 15327: Fix merge intrinsic for strings
- From: Tobias Schlüter <tobias dot schlueter at physik dot uni-muenchen dot de>
- To: Paul Brook <paul at codesourcery dot com>
- Cc: fortran at gcc dot gnu dot org, patch <gcc-patches at gcc dot gnu dot org>
- Date: Thu, 02 Sep 2004 00:37:14 +0200
- Subject: Re: [gfortran] PR 15327: Fix merge intrinsic for strings
- References: <4132460D.20900@physik.uni-muenchen.de> <200409012236.14013.paul@codesourcery.com>
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));
! }
}