re PR fortran/15327 (ICE when using MERGE on strings)
authorTobias Schlüter <tobias.schlueter@physik.uni-muenchen.de>
Wed, 1 Sep 2004 23:29:46 +0000 (01:29 +0200)
committerTobias Schlüter <tobi@gcc.gnu.org>
Wed, 1 Sep 2004 23:29:46 +0000 (01:29 +0200)
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
gcc/fortran/trans-intrinsic.c
gcc/testsuite/ChangeLog
gcc/testsuite/gfortran.dg/merge_char_1.f90 [new file with mode: 0644]

index 1c792b97a493bc8590594f4b3530ec107950b7f5..abeaaaaeb43eb167b36f637a7a3ec2af25d3a1b8 100644 (file)
@@ -1,3 +1,9 @@
+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.
+
 2004-09-01  Tobias Schlueter  <tobias.schlueter@physik.uni-muenchen.de>
 
        PR fortran/16400
index bdb307f60ff5ae3971ae8e6c0e64fe6990dbad47..79d668983514b26186d06b09fe32fde2f8b22953 100644 (file)
@@ -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));
 }
index ba2a71374773664b8108dcff620e981dc3a98d47..da0463cacf477eab2639643d3cebf08620503079 100644 (file)
@@ -1,3 +1,8 @@
+2004-09-01  Tobias Schlueter  <tobias.schlueter@physik.uni-muenchen.de>
+
+       PR fortran/15327
+       * gfortran.dg/merge_char_1.f90: New test.
+
 2004-09-01  Tobias Schlueter  <tobias.schlueter@physik.uni-muenchen.de>
 
        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 (file)
index 0000000..0a8036d
--- /dev/null
@@ -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