re PR fortran/31608 (wrong types in character array/scalar binop)
authorPaul Thomas <pault@gcc.gnu.org>
Sun, 18 Nov 2007 17:14:40 +0000 (17:14 +0000)
committerPaul Thomas <pault@gcc.gnu.org>
Sun, 18 Nov 2007 17:14:40 +0000 (17:14 +0000)
2007-11-18  Paul Thomas  <pault@gcc.gnu.org>

PR fortran/31608
* trans-array.c (gfc_conv_expr_descriptor): Remove exception
for indirect references in the call to gfc_trans_scalar_assign.
* trans-expr.c (gfc_conv_string_parameter): Instead of asserting
that the expression is not an indirect reference, cast it to a
pointer type of the length given by se->string_length.

2007-11-18  Paul Thomas  <pault@gcc.gnu.org>

PR fortran/31608
* gfortran.dg/char_cast_2.f90: New test based on achar_4.f90.

From-SVN: r130271

gcc/fortran/ChangeLog
gcc/fortran/trans-array.c
gcc/fortran/trans-expr.c
gcc/testsuite/ChangeLog
gcc/testsuite/gfortran.dg/char_cast_2.f90 [new file with mode: 0644]

index f95ca66..0155ed1 100644 (file)
@@ -1,3 +1,12 @@
+2007-11-18  Paul Thomas  <pault@gcc.gnu.org>
+
+       PR fortran/31608
+       * trans-array.c (gfc_conv_expr_descriptor): Remove exception
+       for indirect references in the call to gfc_trans_scalar_assign.
+       * trans-expr.c (gfc_conv_string_parameter): Instead of asserting
+       that the expression is not an indirect reference, cast it to a
+       pointer type of the length given by se->string_length.
+
 2007-11-18  Tobias Burnus  <burnus@net-b.de>
 
        PR fortran/34137
index c418ae2..315279a 100644 (file)
@@ -4734,15 +4734,10 @@ gfc_conv_expr_descriptor (gfc_se * se, gfc_expr * expr, gfc_ss * ss)
       gfc_add_block_to_block (&block, &rse.pre);
       gfc_add_block_to_block (&block, &lse.pre);
 
-      if (TREE_CODE (rse.expr) != INDIRECT_REF)
-       {
-         lse.string_length = rse.string_length;
-         tmp = gfc_trans_scalar_assign (&lse, &rse, expr->ts, true,
-                                 expr->expr_type == EXPR_VARIABLE);
-         gfc_add_expr_to_block (&block, tmp);
-       }
-      else
-       gfc_add_modify_expr (&block, lse.expr, rse.expr);
+      lse.string_length = rse.string_length;
+      tmp = gfc_trans_scalar_assign (&lse, &rse, expr->ts, true,
+                                    expr->expr_type == EXPR_VARIABLE);
+      gfc_add_expr_to_block (&block, tmp);
 
       /* Finish the copying loops.  */
       gfc_trans_scalarizing_loops (&loop, &block);
index a1f1ee9..ec5a73a 100644 (file)
@@ -3597,8 +3597,15 @@ gfc_conv_string_parameter (gfc_se * se)
   type = TREE_TYPE (se->expr);
   if (TYPE_STRING_FLAG (type))
     {
-      gcc_assert (TREE_CODE (se->expr) != INDIRECT_REF);
-      se->expr = gfc_build_addr_expr (pchar_type_node, se->expr);
+      if (TREE_CODE (se->expr) != INDIRECT_REF)
+        se->expr = gfc_build_addr_expr (pchar_type_node, se->expr);
+      else
+       {
+         type = gfc_get_character_type_len (gfc_default_character_kind,
+                                            se->string_length);
+         type = build_pointer_type (type);
+         se->expr = gfc_build_addr_expr (type, se->expr);
+       }
     }
 
   gcc_assert (POINTER_TYPE_P (TREE_TYPE (se->expr)));
index 5ea2a0e..6d3bd10 100644 (file)
@@ -1,3 +1,8 @@
+2007-11-18  Paul Thomas  <pault@gcc.gnu.org>
+
+       PR fortran/31608
+       * gfortran.dg/char_cast_2.f90: New test based on achar_4.f90.
+
 2007-11-18  Tobias Burnus  <burnus@net-b.de>
 
        PR fortran/34137
diff --git a/gcc/testsuite/gfortran.dg/char_cast_2.f90 b/gcc/testsuite/gfortran.dg/char_cast_2.f90
new file mode 100644 (file)
index 0000000..39566da
--- /dev/null
@@ -0,0 +1,26 @@
+! { dg-do compile }
+! { dg-options "-fdump-tree-original" }
+! This is the same as achar_4.f90 but checks that the result of the 'merge'
+! reference is correctly cast.
+!
+! The code comes from http://www.star.le.ac.uk/~cgp/fortran.html (by Clive Page)
+! Reported by Thomas Koenig <tkoenig@gcc.gnu.org>
+!
+  if (any (Up ("AbCdEfGhIjKlM") .ne. (/"ABCDEFGHIJKLM"/))) call abort ()
+contains
+  Character (len=20) Function Up (string)
+    Character(len=*) string
+    Up =                                                                &
+     transfer(merge(achar(iachar(transfer(string,"x",len(string)))-     &
+     (ichar('a')-ichar('A')) ),                                         &
+     transfer(string,"x",len(string)) ,                                 &
+     transfer(string,"x",len(string)) >= "a" .and.                      &
+     transfer(string,"x",len(string)) <= "z"), repeat("x", len(string)))
+    return
+  end function Up
+end
+! The sign that all is well is that [S.5][1] appears five times.
+! Platform dependent variations are [S$5][1], [__S_5][1], [S___5][1]
+! so we count the occurrences of 5][1].
+! { dg-final { scan-tree-dump-times "5\\\]\\\[1\\\]" 5 "original" } }
+! { dg-final { cleanup-tree-dump "original" } }