Patchwork [Fortran] Fix type decl of coarrays

login
register
mail settings
Submitter Tobias Burnus
Date May 28, 2011, 6:24 a.m.
Message ID <4DE09530.2020103@net-b.de>
Download mbox | patch
Permalink /patch/97770/
State New
Headers show

Comments

Tobias Burnus - May 28, 2011, 6:24 a.m.
Thanks for Richard for debugging this!

Setting TREE_TYPE in trans-decl.c is nonsense and leads to types of the 
form "_Complex _Complex int". The fix is rather obvious.

Build and regtested on x86-64-linux.
OK for the trunk?

Tobias
Steve Kargl - May 29, 2011, 5:24 p.m.
On Sat, May 28, 2011 at 08:24:48AM +0200, Tobias Burnus wrote:
> Thanks for Richard for debugging this!
> 
> Setting TREE_TYPE in trans-decl.c is nonsense and leads to types of the 
> form "_Complex _Complex int". The fix is rather obvious.
> 
> Build and regtested on x86-64-linux.
> OK for the trunk?
> 

OK.  (Yes, I read the exchange between you and Richi in this
thread).

Patch

2011-05-28  Tobias Burnus  <burnus@net-b.de>

        PR fortran/18918
	* trans-types.c (gfc_get_nodesc_array_type): Don't mess with
	the type's TREE_TYPE.
	* trans-array.c (gfc_conv_array_ref): Use TYPE_MAIN_VARIANT.
	* trans.c (gfc_build_array_ref): Ditto.

2011-05-28  Tobias Burnus  <burnus@net-b.de>

        PR fortran/18918
	* gfortran.dg/coarray_23.f90: New.

diff --git a/gcc/fortran/trans-array.c b/gcc/fortran/trans-array.c
index b2992f0..d83a7a9 100644
--- a/gcc/fortran/trans-array.c
+++ b/gcc/fortran/trans-array.c
@@ -2628,7 +2628,7 @@  gfc_conv_array_ref (gfc_se * se, gfc_array_ref * ar, gfc_symbol * sym,
 	se->expr = build_fold_indirect_ref_loc (input_location, se->expr);
 
       /* Use the actual tree type and not the wrapped coarray. */
-      se->expr = fold_convert (TREE_TYPE (TREE_TYPE (se->expr)), se->expr);
+      se->expr = fold_convert (TYPE_MAIN_VARIANT (TREE_TYPE (se->expr)), se->expr);
       return;
     }
 
diff --git a/gcc/fortran/trans-types.c b/gcc/fortran/trans-types.c
index 94b9a59..02a75fd 100644
--- a/gcc/fortran/trans-types.c
+++ b/gcc/fortran/trans-types.c
@@ -1423,10 +1423,7 @@  gfc_get_nodesc_array_type (tree etype, gfc_array_spec * as, gfc_packed packed,
   if (as->rank)
     type = make_node (ARRAY_TYPE);
   else
-    {
-      type = build_variant_type_copy (etype);
-      TREE_TYPE (type) = etype;
-    }
+    type = build_variant_type_copy (etype);
 
   GFC_ARRAY_TYPE_P (type) = 1;
   TYPE_LANG_SPECIFIC (type)
diff --git a/gcc/fortran/trans.c b/gcc/fortran/trans.c
index fcbb850..0ab4637 100644
--- a/gcc/fortran/trans.c
+++ b/gcc/fortran/trans.c
@@ -320,7 +320,7 @@  gfc_build_array_ref (tree base, tree offset, tree decl)
     {
       gcc_assert (GFC_TYPE_ARRAY_CORANK (type) > 0);
 
-      return fold_convert (TREE_TYPE (type), base);
+      return fold_convert (TYPE_MAIN_VARIANT (type), base);
     }
 
   gcc_assert (TREE_CODE (type) == ARRAY_TYPE);
--- /dev/null	2011-05-27 20:00:22.465849134 +0200
+++ gcc/gcc/testsuite/gfortran.dg/coarray_23.f90	2011-05-28 08:03:35.000000000 +0200
@@ -0,0 +1,13 @@ 
+! { dg-do compile }
+! { dg-options "-fcoarray=single" }
+!
+! PR fortran/18918
+!
+! The example was ICEing before as the tree-decl
+! of the type was wrong.
+!
+
+  subroutine test
+    complex, save :: z[*]
+    if (z /= cmplx (0.0, 0.0)) call abort()
+  end subroutine test