From c3d0559da5e101d454cc4e90d67f08d11ea1036c Mon Sep 17 00:00:00 2001 From: =?utf8?q?Tobias=20Schl=C3=BCter?= Date: Thu, 2 Sep 2004 01:29:46 +0200 Subject: [PATCH] re PR fortran/15327 (ICE when using MERGE on strings) fortran/ PR fortran/15327 * trans-intrinsic.c (gfc_conv_intrinsic_merge): Do the right thing for strings. testsuite/ PR fortran/15327 * gfortran.dg/merge_char_1.f90: New test. From-SVN: r86940 --- gcc/fortran/ChangeLog | 6 +++++ gcc/fortran/trans-intrinsic.c | 26 +++++++++++++++++----- gcc/testsuite/ChangeLog | 5 +++++ gcc/testsuite/gfortran.dg/merge_char_1.f90 | 7 ++++++ 4 files changed, 39 insertions(+), 5 deletions(-) create mode 100644 gcc/testsuite/gfortran.dg/merge_char_1.f90 diff --git a/gcc/fortran/ChangeLog b/gcc/fortran/ChangeLog index 1c792b97a49..abeaaaaeb43 100644 --- a/gcc/fortran/ChangeLog +++ b/gcc/fortran/ChangeLog @@ -1,3 +1,9 @@ +2004-09-01 Tobias Schlueter + + PR fortran/15327 + * trans-intrinsic.c (gfc_conv_intrinsic_merge): Do the right thing for + strings. + 2004-09-01 Tobias Schlueter PR fortran/16400 diff --git a/gcc/fortran/trans-intrinsic.c b/gcc/fortran/trans-intrinsic.c index bdb307f60ff..79d66898351 100644 --- a/gcc/fortran/trans-intrinsic.c +++ b/gcc/fortran/trans-intrinsic.c @@ -1998,14 +1998,30 @@ gfc_conv_intrinsic_merge (gfc_se * se, gfc_expr * expr) tree fsource; tree mask; tree type; + tree len; 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); + if (expr->ts.type != BT_CHARACTER) + { + tsource = TREE_VALUE (arg); + arg = TREE_CHAIN (arg); + fsource = TREE_VALUE (arg); + mask = TREE_VALUE (TREE_CHAIN (arg)); + } + 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)); + se->string_length = len; + } type = TREE_TYPE (tsource); se->expr = fold (build3 (COND_EXPR, type, mask, tsource, fsource)); } diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index ba2a7137477..da0463cacf4 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2004-09-01 Tobias Schlueter + + PR fortran/15327 + * gfortran.dg/merge_char_1.f90: New test. + 2004-09-01 Tobias Schlueter PR fortran/16404 diff --git a/gcc/testsuite/gfortran.dg/merge_char_1.f90 b/gcc/testsuite/gfortran.dg/merge_char_1.f90 new file mode 100644 index 00000000000..0a8036d62df --- /dev/null +++ b/gcc/testsuite/gfortran.dg/merge_char_1.f90 @@ -0,0 +1,7 @@ +! { dg-do run } +! PR 15327 +! The merge intrinsic didn't work for strings +character*2 :: c(2) +c = merge( (/ "AA", "BB" /), (/ "CC", "DD" /), (/ .TRUE., .FALSE. /) ) +if (c(1).ne."AA" .or. c(2).ne."DD") call abort () +end -- 2.30.2