This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] Fix Fortran DATA range constructors of CHARACTER arrays


Hi!

The following testcase results in really weird assembly and fails:
c.802:
        .ascii  "A   "
        .zero   18446744073709551613
        .ascii  "A"
        .zero   3
        .ascii  "A"
        .zero   3
        .zero   3
a.801:
        .ascii  "A   "
        .ascii  "A   "
        .ascii  "A   "
b.800:
        .ascii  "A"
        .zero   3
        .ascii  "A"
        .zero   3
        .ascii  "A"
        .zero   3
IMHO all 3 variables should be equal, the same as a.801 above.
The patch below cures this, create_character_initializer is called
just from gfc_assign_data_value but not from gfc_assign_data_value_range.
In gfc_assign_data_value_range we know ref is NULL, but last_ts->type
can be BT_CHARACTER as exhibited by the testcase.
:ADDPATCH fortran:

Ok for HEAD/4.0?

2005-07-19  Jakub Jelinek  <jakub@redhat.com>

	* data.c (gfc_assign_data_value_range): Call
	create_character_initializer if last_ts is a character type.

	* gfortran.fortran-torture/execute/data_4.f90: New test.

--- gcc/fortran/data.c.jj	2005-07-19 17:39:28.000000000 +0200
+++ gcc/fortran/data.c	2005-07-19 17:39:48.000000000 +0200
@@ -459,12 +459,17 @@ gfc_assign_data_value_range (gfc_expr * 
       last_con = con;
     }
 
-  /* We should never be overwriting an existing initializer.  */
-  gcc_assert (!init);
+  if (last_ts->type == BT_CHARACTER)
+    expr = create_character_intializer (init, last_ts, NULL, rvalue);
+  else
+    {
+      /* We should never be overwriting an existing initializer.  */
+      gcc_assert (!init);
 
-  expr = gfc_copy_expr (rvalue);
-  if (!gfc_compare_types (&lvalue->ts, &expr->ts))
-    gfc_convert_type (expr, &lvalue->ts, 0);
+      expr = gfc_copy_expr (rvalue);
+      if (!gfc_compare_types (&lvalue->ts, &expr->ts))
+	gfc_convert_type (expr, &lvalue->ts, 0);
+    }
 
   if (last_con == NULL)
     symbol->value = expr;
--- gcc/testsuite/gfortran.fortran-torture/execute/data_4.f90.jj	2005-07-19 17:48:25.000000000 +0200
+++ gcc/testsuite/gfortran.fortran-torture/execute/data_4.f90	2005-07-19 15:10:45.000000000 +0200
@@ -0,0 +1,6 @@
+	CHARACTER*4 A(3),B(3),C(3)
+	DATA A /'A',"A",'A'/
+	DATA B /3*'A'/
+	DATA C /'A', 2*'A'/
+	IF (ANY(A.NE.B).OR.ANY(A.NE.C)) CALL ABORT
+	END

	Jakub


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]