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]

[tree-ssa] check for, and fix, type mismatches across &/*/[].


Looking at the remaining cases that fold_stmt can't turn *(&V + C)
into a more structured construct, it would appear that they are ALL
front-end bugs.  To wit, there's a cast missing.

This happens when someone builds an ADDR_EXPR or INDIRECT_REF node
by hand, and fails to make sure that the types match.

The following patch adds an ENABLE_CHECKING test to the gimplifier
to validate all such nodes.  If and when we create a verify_stmt,
this should probably be moved there.

I also fix all ocurrences of this bug that appear in the test suites.

Looking at this, I'm more or less of the opinion that there are 
almost certainly latent bugs, and that any time one builds either of
these nodes by hand, you're probably wrong.  We should move the C++
helper routines build_address and build_indirect_ref (or workalikes)
to tree.c and force everyone to use them.


r~


        * except.c (output_function_exception_table): Strip nops.
        * gimplify.c (gimplify_addr_expr): Kill missing cast workaround.
        (cpt_same_type, check_pointer_types_r): New.
        (gimplify_body): Call it.
        * tree-inline.c (insert_decl_map): New.
        (remap_decl, remap_type, remap_block, copy_body_r,
        initialize_inlined_parameters, declare_return_variable,
        remap_save_expr, mark_local_for_remap_r): Use it.
cp/
        * call.c (build_java_interface_fn_ref): Use build_address+convert.
        * except.c (build_eh_type_type): Likewise.
        * class.c (build_base_path): Use convert+build_indirect_ref.
        * init.c (expand_virtual_init): Likewise.
        * rtti.c (get_tinfo_decl_dynamic): Use convert.
fortran/
        * trans-array.c (gfc_trans_allocate_array_storage): Use convert.
        (gfc_conv_array_base): Likewise.
        * trans-decl.c (gfc_trans_auto_character_variable): Likewise.
        * trans-expr.c (gfc_conv_string_tmp): Likewise.
        * trans-intrinsic.c (gfc_conv_intrinsic_trim): Likewise.
        * trans-stmt.c (gfc_trans_character_select): Likewise.
java/
        * class.c (build_indirect_class_ref): Use convert.
        * constants.c (build_constant_data_ref): Fix type on the decl
        and return that directly.
        (build_constants_constructor): Remove kruft to match.
        (build_ref_from_constant_pool): Use ARRAY_REF.
        * expr.c (build_java_indirect_ref): Use convert.
        (build_known_method_ref): Likewise.
        * parse.y (patch_string_cst): Likewise.

Index: gcc/except.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/except.c,v
retrieving revision 1.227.2.20
diff -u -p -r1.227.2.20 except.c
--- gcc/except.c	13 Nov 2003 02:37:51 -0000	1.227.2.20
+++ gcc/except.c	20 Nov 2003 23:19:28 -0000
@@ -3927,6 +3927,7 @@ output_function_exception_table (void)
 	  /* Let cgraph know that the rtti decl is used.  Not all of the
 	     paths below go through assemble_integer, which would take
 	     care of this for us.  */
+	  STRIP_NOPS (type);
 	  if (TREE_CODE (type) == ADDR_EXPR)
 	    {
 	      type = TREE_OPERAND (type, 0);
Index: gcc/gimplify.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/Attic/gimplify.c,v
retrieving revision 1.1.2.120
diff -u -p -r1.1.2.120 gimplify.c
--- gcc/gimplify.c	20 Nov 2003 20:54:38 -0000	1.1.2.120
+++ gcc/gimplify.c	20 Nov 2003 23:19:30 -0000
@@ -2397,20 +2397,6 @@ gimplify_addr_expr (tree *expr_p, tree *
       /* This added an INDIRECT_REF.  Fold it away.  */
       op0 = TREE_OPERAND (TREE_OPERAND (expr, 0), 0);
 
-      /* ??? The Fortran front end does questionable things with types here,
-	 wanting to create a pointer to an array by taking the address of
-	 an element of the array.  I think we're trying to create some sort
-	 of array slice or something.  Anyway, notice that the type of the
-	 ADDR_EXPR doesn't match the type of the current pointer and add a
-	 cast if necessary.  */
-      if (TYPE_MAIN_VARIANT (TREE_TYPE (expr))
-	  != TYPE_MAIN_VARIANT (TREE_TYPE (op0)))
-	{
-	  op0 = build1 (NOP_EXPR, TREE_TYPE (expr), op0);
-	  if (ret != GS_ERROR)
-	    ret = GS_OK;
-	}
-
       *expr_p = op0;
       break;
 
@@ -3323,6 +3309,77 @@ gimplify_expr (tree *expr_p, tree *pre_p
   return ret;
 }
 
+#ifdef ENABLE_CHECKING
+/* Compare types A and B for a "close enough" match.  */
+
+static bool
+cpt_same_type (tree a, tree b)
+{
+  if (TYPE_MAIN_VARIANT (a) == TYPE_MAIN_VARIANT (b))
+    return true;
+
+  /* ??? Ug.  METHOD_TYPES decompose to FUNCTION_TYPES and they aren't
+     linked together.  Since this routine is intended to catch type errors
+     that will affect the optimizers, and the optimizers don't add new
+     dereferences of function pointers, so ignore it.  */
+  if ((TREE_CODE (a) == FUNCTION_TYPE || TREE_CODE (a) == METHOD_TYPE)
+      && (TREE_CODE (b) == FUNCTION_TYPE || TREE_CODE (b) == METHOD_TYPE))
+    return true;
+
+  /* And because of that, we have to recurse down through pointers.  */
+  if (POINTER_TYPE_P (a) && POINTER_TYPE_P (b))
+    return cpt_same_type (TREE_TYPE (a), TREE_TYPE (b));
+
+  return false;
+}
+
+/* Check for some cases of the front end missing cast expressions.
+   The type of a dereference should correspond to the pointer type;
+   similarly the type of an address should match its object.  */
+
+static tree
+check_pointer_types_r (tree *tp, int *walk_subtrees ATTRIBUTE_UNUSED,
+		       void *data ATTRIBUTE_UNUSED)
+{
+  tree t = *tp;
+  tree ptype, otype, dtype;
+
+  switch (TREE_CODE (t))
+    {
+    case INDIRECT_REF:
+    case ARRAY_REF:
+      otype = TREE_TYPE (t);
+      ptype = TREE_TYPE (TREE_OPERAND (t, 0));
+      dtype = TREE_TYPE (ptype);
+      if (!cpt_same_type (otype, dtype))
+	abort ();
+      break;
+
+    case ADDR_EXPR:
+      ptype = TREE_TYPE (t);
+      otype = TREE_TYPE (TREE_OPERAND (t, 0));
+      dtype = TREE_TYPE (ptype);
+      if (!cpt_same_type (otype, dtype))
+	{
+	  /* &array is allowed to produce a pointer to the element,
+	     rather than a pointer to the array type.  */
+	  if (TREE_CODE (otype) == ARRAY_TYPE
+	      && POINTER_TYPE_P (ptype)
+	      && cpt_same_type (TREE_TYPE (otype), dtype))
+	    break;
+	  abort ();
+	}
+      break;
+
+    default:
+      return NULL_TREE;
+    }
+
+
+  return NULL_TREE;
+}
+#endif
+
 /* Gimplify the body of statements pointed by BODY_P.  FNDECL is the
    function decl containing BODY.  */
 
@@ -3369,6 +3426,11 @@ gimplify_body (tree *body_p, tree fndecl
   declare_tmp_vars (gimplify_ctxp->temps, body);
 
   pop_gimplify_context ();
+
+#ifdef ENABLE_CHECKING
+  walk_tree (body_p, check_pointer_types_r, NULL, NULL);
+#endif
+
   timevar_pop (TV_TREE_GIMPLIFY);
   input_location = saved_location;
 }
Index: gcc/tree-inline.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/tree-inline.c,v
retrieving revision 1.26.2.63
diff -u -p -r1.26.2.63 tree-inline.c
--- gcc/tree-inline.c	20 Nov 2003 21:21:44 -0000	1.26.2.63
+++ gcc/tree-inline.c	20 Nov 2003 23:19:32 -0000
@@ -137,6 +137,21 @@ static tree mark_local_for_remap_r (tree
 static tree unsave_r (tree *, int *, void *);
 static void declare_inline_vars (tree bind_expr, tree vars);
 
+/* Insert a tree->tree mapping for ID.  Despite the name suggests
+   that the trees should be variables, it is used for more than that.  */
+
+static void
+insert_decl_map (inline_data *id, tree key, tree value)
+{
+  splay_tree_insert (id->decl_map, (splay_tree_key) key,
+		     (splay_tree_value) value);
+
+  /* Always insert an identity map as well.  If we see this same new
+     node again, we won't want to duplicate it a second time.  */
+  if (key != value)
+    splay_tree_insert (id->decl_map, (splay_tree_key) value,
+		       (splay_tree_value) value);
+}
 
 /* Remap DECL during the copying of the BLOCK tree for the function.  */
 
@@ -205,9 +220,8 @@ remap_decl (tree decl, inline_data *id)
 
       /* Remember it, so that if we encounter this local entity
 	 again we can reuse this copy.  */
-      n = splay_tree_insert (id->decl_map,
-			     (splay_tree_key) decl,
-			     (splay_tree_value) t);
+      insert_decl_map (id, decl, t);
+      return t;
     }
 
   return (tree) n->value;
@@ -230,15 +244,13 @@ remap_type (tree type, inline_data *id)
   /* The type only needs remapping if it's variably modified.  */
   if (! variably_modified_type_p (type))
     {
-      splay_tree_insert (id->decl_map, (splay_tree_key) type,
-			 (splay_tree_value) type);
+      insert_decl_map (id, type, type);
       return type;
     }
   
   /* We do need a copy.  build and register it now.  */
   new = copy_node (type);
-  splay_tree_insert (id->decl_map, (splay_tree_key) type,
-		     (splay_tree_value) new);
+  insert_decl_map (id, type, new);
 
   /* This is a new type, not a copy of an old type.  Need to reassociate
      variants.  We can handle everything except the main variant lazily.  */
@@ -395,9 +407,7 @@ remap_block (tree *block, inline_data *i
     }
 #endif
   /* Remember the remapped block.  */
-  splay_tree_insert (id->decl_map,
-		     (splay_tree_key) old_block,
-		     (splay_tree_value) new_block);
+  insert_decl_map (id, old_block, new_block);
 }
 
 static void
@@ -522,9 +532,7 @@ copy_body_r (tree *tp, int *walk_subtree
          will refer to it, so save a copy ready for remapping.  We
          save it in the decl_map, although it isn't a decl.  */
       tree new_block = copy_node (*tp);
-      splay_tree_insert (id->decl_map,
-			 (splay_tree_key) *tp,
-			 (splay_tree_value) new_block);
+      insert_decl_map (id, *tp, new_block);
       *tp = new_block;
     }
   else if (TREE_CODE (*tp) == EXIT_BLOCK_EXPR)
@@ -709,9 +717,7 @@ initialize_inlined_parameters (inline_da
 	      else if (TREE_TYPE (value) != TREE_TYPE (p))
 		value = fold (build1 (NOP_EXPR, TREE_TYPE (p), value));
 
-	      splay_tree_insert (id->decl_map,
-				 (splay_tree_key) p,
-				 (splay_tree_value) value);
+	      insert_decl_map (id, p, value);
 	      continue;
 	    }
 	}
@@ -732,9 +738,7 @@ initialize_inlined_parameters (inline_da
       /* Register the VAR_DECL as the equivalent for the PARM_DECL;
 	 that way, when the PARM_DECL is encountered, it will be
 	 automatically replaced by the VAR_DECL.  */
-      splay_tree_insert (id->decl_map,
-			 (splay_tree_key) p,
-			 (splay_tree_value) var_sub);
+      insert_decl_map (id, p, var_sub);
 
       /* Declare this new variable.  */
       TREE_CHAIN (var) = vars;
@@ -834,9 +838,7 @@ declare_return_variable (inline_data *id
   /* Register the VAR_DECL as the equivalent for the RESULT_DECL; that
      way, when the RESULT_DECL is encountered, it will be
      automatically replaced by the VAR_DECL.  */
-  splay_tree_insert (id->decl_map,
-		     (splay_tree_key) result,
-		     (splay_tree_value) var);
+  insert_decl_map (id, result, var);
 
   /* Remember this so we can ignore it in remap_decls.  */
   id->retvar = var;
@@ -2108,6 +2110,7 @@ remap_save_expr (tree *tp, void *st_, tr
 {
   splay_tree st = (splay_tree) st_;
   splay_tree_node n;
+  tree t;
 
   /* See if we already encountered this SAVE_EXPR.  */
   n = splay_tree_lookup (st, (splay_tree_key) *tp);
@@ -2115,7 +2118,7 @@ remap_save_expr (tree *tp, void *st_, tr
   /* If we didn't already remap this SAVE_EXPR, do so now.  */
   if (!n)
     {
-      tree t = copy_node (*tp);
+      t = copy_node (*tp);
 
       /* The SAVE_EXPR is now part of the function into which we
 	 are inlining this body.  */
@@ -2123,19 +2126,19 @@ remap_save_expr (tree *tp, void *st_, tr
       /* And we haven't evaluated it yet.  */
       SAVE_EXPR_RTL (t) = NULL_RTX;
       /* Remember this SAVE_EXPR.  */
-      n = splay_tree_insert (st,
-			     (splay_tree_key) *tp,
-			     (splay_tree_value) t);
+      splay_tree_insert (st, (splay_tree_key) *tp, (splay_tree_value) t);
       /* Make sure we don't remap an already-remapped SAVE_EXPR.  */
       splay_tree_insert (st, (splay_tree_key) t, (splay_tree_value) t);
     }
   else
-    /* We've already walked into this SAVE_EXPR, so we needn't do it
-       again.  */
-    *walk_subtrees = 0;
+    {
+      /* We've already walked into this SAVE_EXPR; don't do it again.  */
+      *walk_subtrees = 0;
+      t = (tree) n->value;
+    }
 
   /* Replace this SAVE_EXPR with the copy.  */
-  *tp = (tree) n->value;
+  *tp = t;
 }
 
 /* Called via walk_tree.  If *TP points to a DECL_STMT for a local
@@ -2148,7 +2151,6 @@ mark_local_for_remap_r (tree *tp, int *w
 {
   tree t = *tp;
   inline_data *id = (inline_data *) data;
-  splay_tree st = id->decl_map;
   tree decl;
 
   /* Don't walk into types.  */
@@ -2174,9 +2176,7 @@ mark_local_for_remap_r (tree *tp, int *w
 				     DECL_CONTEXT (decl));
 
       /* Remember the copy.  */
-      splay_tree_insert (st,
-			 (splay_tree_key) decl, 
-			 (splay_tree_value) copy);
+      insert_decl_map (id, decl, copy);
     }
 
   return NULL_TREE;
Index: gcc/cp/call.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/call.c,v
retrieving revision 1.320.2.37
diff -u -p -r1.320.2.37 call.c
--- gcc/cp/call.c	18 Nov 2003 06:24:31 -0000	1.320.2.37
+++ gcc/cp/call.c	20 Nov 2003 23:19:48 -0000
@@ -4717,7 +4717,8 @@ build_java_interface_fn_ref (tree fn, tr
 		iface);
       return error_mark_node;
     }
-  iface_ref = build1 (ADDR_EXPR, build_pointer_type (iface), iface_ref);
+  iface_ref = build_address (iface_ref);
+  iface_ref = convert (build_pointer_type (iface), iface_ref);
   
   /* Determine the itable index of FN.  */
   i = 1;
Index: gcc/cp/class.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/class.c,v
retrieving revision 1.452.2.31
diff -u -p -r1.452.2.31 class.c
--- gcc/cp/class.c	13 Nov 2003 02:38:50 -0000	1.452.2.31
+++ gcc/cp/class.c	20 Nov 2003 23:19:54 -0000
@@ -309,14 +309,14 @@ build_base_path (enum tree_code code,
 	  /* In a base member initializer, we cannot rely on
 	     the vtable being set up. We have to use the vtt_parm.  */
 	  tree derived = BINFO_INHERITANCE_CHAIN (v_binfo);
-	  
-	  v_offset = build (PLUS_EXPR, TREE_TYPE (current_vtt_parm),
-			    current_vtt_parm, BINFO_VPTR_INDEX (derived));
-	  
-	  v_offset = build1 (INDIRECT_REF,
-			     TREE_TYPE (TYPE_VFIELD (BINFO_TYPE (derived))),
-			     v_offset);
-	  
+	  tree t;
+
+	  t = TREE_TYPE (TYPE_VFIELD (BINFO_TYPE (derived)));
+	  t = build_pointer_type (t);
+	  v_offset = convert (t, current_vtt_parm);
+	  v_offset = build (PLUS_EXPR, t, v_offset,
+			    BINFO_VPTR_INDEX (derived));
+	  v_offset = build_indirect_ref (v_offset, NULL);
 	}
       else
 	v_offset = build_vfield_ref (build_indirect_ref (expr, NULL),
Index: gcc/cp/except.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/except.c,v
retrieving revision 1.142.2.15
diff -u -p -r1.142.2.15 except.c
--- gcc/cp/except.c	18 Nov 2003 06:24:32 -0000	1.142.2.15
+++ gcc/cp/except.c	20 Nov 2003 23:19:55 -0000
@@ -144,7 +144,7 @@ build_eh_type_type (tree type)
 
   mark_used (exp);
 
-  return build1 (ADDR_EXPR, ptr_type_node, exp);
+  return convert (ptr_type_node, build_address (exp));
 }
 
 tree
Index: gcc/cp/init.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/init.c,v
retrieving revision 1.281.2.31
diff -u -p -r1.281.2.31 init.c
--- gcc/cp/init.c	18 Nov 2003 06:24:32 -0000	1.281.2.31
+++ gcc/cp/init.c	20 Nov 2003 23:19:57 -0000
@@ -761,7 +761,8 @@ expand_virtual_init (tree binfo, tree de
 		     TREE_TYPE (vtt_parm), 
 		     vtt_parm,
 		     vtt_index);
-      vtbl2 = build1 (INDIRECT_REF, TREE_TYPE (vtbl), vtbl2);
+      vtbl2 = build_indirect_ref (vtbl2, NULL);
+      vtbl2 = convert (TREE_TYPE (vtbl), vtbl2);
 
       /* The actual initializer is the VTT value only in the subobject
 	 constructor.  In maybe_clone_body we'll substitute NULL for
Index: gcc/cp/rtti.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/rtti.c,v
retrieving revision 1.135.2.22
diff -u -p -r1.135.2.22 rtti.c
--- gcc/cp/rtti.c	12 Oct 2003 19:43:36 -0000	1.135.2.22
+++ gcc/cp/rtti.c	20 Nov 2003 23:19:58 -0000
@@ -231,7 +231,7 @@ get_tinfo_decl_dynamic (tree exp)
       /* The RTTI information is at index -1.  */
       index = build_int_2 (-1 * TARGET_VTABLE_DATA_ENTRY_DISTANCE, -1);
       t = build_vtbl_ref (exp, index);
-      TREE_TYPE (t) = type_info_ptr_type;
+      t = convert (type_info_ptr_type, t);
     }
   else
     /* Otherwise return the type_info for the static type of the expr.  */
Index: gcc/fortran/trans-array.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/fortran/Attic/trans-array.c,v
retrieving revision 1.1.2.8
diff -u -p -r1.1.2.8 trans-array.c
--- gcc/fortran/trans-array.c	12 Oct 2003 19:43:37 -0000	1.1.2.8
+++ gcc/fortran/trans-array.c	20 Nov 2003 23:20:01 -0000
@@ -447,7 +447,8 @@ gfc_trans_allocate_array_storage (gfc_lo
       tmp = build_array_type (gfc_get_element_type (TREE_TYPE (desc)), tmp);
       tmp = gfc_create_var (tmp, "A");
       TREE_ADDRESSABLE (tmp) = 1;
-      tmp = build1 (ADDR_EXPR, TREE_TYPE (data), tmp);
+      tmp = build1 (ADDR_EXPR, build_pointer_type (TREE_TYPE (tmp)), tmp);
+      tmp = convert (TREE_TYPE (data), tmp);
       info->data = gfc_evaluate_now (tmp, &loop->pre);
 
       gfc_add_modify_expr (&loop->pre, data, info->data);
@@ -456,7 +457,8 @@ gfc_trans_allocate_array_storage (gfc_lo
   else
     {
       /* Allocate memory to hold the data.  */
-      info->pdata = build1 (ADDR_EXPR, ppvoid_type_node, data);
+      tmp = build1 (ADDR_EXPR, build_pointer_type (TREE_TYPE (data)), data);
+      info->pdata = convert (ppvoid_type_node, tmp);
 
       /* Build a call to allocate storage.  */
       args = gfc_chainon_list (NULL_TREE, info->pdata);
@@ -1171,7 +1173,9 @@ gfc_conv_array_base (tree descriptor)
 
           base = build (ARRAY_REF, gfc_get_element_type (type), descriptor,
                         base);
-          base = build1 (ADDR_EXPR, gfc_array_dataptr_type (descriptor), base);
+          base = build1 (ADDR_EXPR, build_pointer_type (TREE_TYPE (base)),
+			 base);
+	  base = convert (gfc_array_dataptr_type (descriptor), base);
         }
       return base;
     }
Index: gcc/fortran/trans-decl.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/fortran/Attic/trans-decl.c,v
retrieving revision 1.1.2.18
diff -u -p -r1.1.2.18 trans-decl.c
--- gcc/fortran/trans-decl.c	13 Nov 2003 22:42:18 -0000	1.1.2.18
+++ gcc/fortran/trans-decl.c	20 Nov 2003 23:20:03 -0000
@@ -1492,6 +1492,7 @@ gfc_build_builtin_function_decls (void)
 static tree
 gfc_trans_auto_character_variable (gfc_symbol * sym, tree fnbody)
 {
+  tree ptr_to_decl;
   tree tmp;
   tree args;
   tree len;
@@ -1507,9 +1508,11 @@ gfc_trans_auto_character_variable (gfc_s
   len = gfc_conv_init_string_length (sym, &block);
 
   TREE_ADDRESSABLE (sym->backend_decl) = 1;
-  tmp = build1 (ADDR_EXPR, ppvoid_type_node, sym->backend_decl);
+  tmp = build_pointer_type (TREE_TYPE (sym->backend_decl));
+  tmp = build1 (ADDR_EXPR, tmp, sym->backend_decl);
+  ptr_to_decl = convert (ppvoid_type_node, tmp);
 
-  args = gfc_chainon_list (NULL_TREE, tmp);
+  args = gfc_chainon_list (NULL_TREE, ptr_to_decl);
   args = gfc_chainon_list (args, len);
   tmp = gfc_build_function_call (gfor_fndecl_internal_malloc, args);
   gfc_add_expr_to_block (&block, tmp);
@@ -1521,9 +1524,7 @@ gfc_trans_auto_character_variable (gfc_s
 
   gfc_start_block (&block);
 
-  tmp = build1 (ADDR_EXPR, ppvoid_type_node, sym->backend_decl);
-
-  args = tree_cons (NULL_TREE, tmp, NULL_TREE);
+  args = gfc_chainon_list (NULL_TREE, ptr_to_decl);
   tmp = gfc_build_function_call (gfor_fndecl_internal_free, args);
   gfc_add_expr_to_block (&block, tmp);
 
Index: gcc/fortran/trans-expr.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/fortran/Attic/trans-expr.c,v
retrieving revision 1.1.2.9
diff -u -p -r1.1.2.9 trans-expr.c
--- gcc/fortran/trans-expr.c	20 Oct 2003 14:44:56 -0000	1.1.2.9
+++ gcc/fortran/trans-expr.c	20 Nov 2003 23:20:04 -0000
@@ -658,7 +658,9 @@ gfc_conv_string_tmp (gfc_se * se, tree t
       tmp = build_array_type (gfc_character1_type_node, tmp);
       var = gfc_create_var (tmp, "str");
       TREE_ADDRESSABLE (var) = 1;
-      var = build1 (ADDR_EXPR, type, var);
+      tmp = build_pointer_type (tmp);
+      var = build1 (ADDR_EXPR, tmp, var);
+      var = convert (type, var);
     }
   else
     {
@@ -667,7 +669,8 @@ gfc_conv_string_tmp (gfc_se * se, tree t
       TREE_ADDRESSABLE (var) = 1;
 
       /* Allocate a temporary to hold the result.  */
-      addr = build1 (ADDR_EXPR, ppvoid_type_node, var);
+      addr = build1 (ADDR_EXPR, build_pointer_type (type), var);
+      addr = convert (ppvoid_type_node, var);
 
       args = NULL_TREE;
       args = gfc_chainon_list (args, addr);
Index: gcc/fortran/trans-intrinsic.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/fortran/Attic/trans-intrinsic.c,v
retrieving revision 1.1.2.19
diff -u -p -r1.1.2.19 trans-intrinsic.c
--- gcc/fortran/trans-intrinsic.c	8 Nov 2003 16:12:33 -0000	1.1.2.19
+++ gcc/fortran/trans-intrinsic.c	20 Nov 2003 23:20:06 -0000
@@ -2998,7 +2998,9 @@ gfc_conv_intrinsic_trim (gfc_se * se, gf
 
   type = build_pointer_type (gfc_character1_type_node);
   var = gfc_create_var (type, "pstr");
-  addr = build1 (ADDR_EXPR, ppvoid_type_node, var);
+  type = build_pointer_type (type);
+  addr = build1 (ADDR_EXPR, type, var);
+  addr = convert (ppvoid_type_node, addr);
   len = gfc_create_var (gfc_int4_type_node, "len");
 
   tmp = gfc_conv_intrinsic_function_args (se, expr);
Index: gcc/fortran/trans-stmt.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/fortran/Attic/trans-stmt.c,v
retrieving revision 1.1.2.8
diff -u -p -r1.1.2.8 trans-stmt.c
--- gcc/fortran/trans-stmt.c	20 Oct 2003 14:44:56 -0000	1.1.2.8
+++ gcc/fortran/trans-stmt.c	20 Nov 2003 23:20:08 -0000
@@ -851,7 +851,7 @@ gfc_trans_logical_select (gfc_code * cod
 static tree
 gfc_trans_character_select (gfc_code *code)
 {
-  tree init, node, end_label, tmp, args, *labels;
+  tree init, node, end_label, tmp, type, args, *labels;
   stmtblock_t block, body;
   gfc_case *cp, *d;
   gfc_code *c;
@@ -973,15 +973,15 @@ gfc_trans_character_select (gfc_code *co
       init = tree_cons (NULL_TREE, tmp, init);
     }
 
-  tmp = build_array_type (select_struct,
-                          build_index_type (build_int_2(n - 1, 0)));
+  type = build_array_type (select_struct,
+                           build_index_type (build_int_2(n - 1, 0)));
 
-  init = build1 (CONSTRUCTOR, tmp, nreverse(init));
+  init = build1 (CONSTRUCTOR, type, nreverse(init));
   TREE_CONSTANT (init) = 1;
   TREE_INVARIANT (init) = 1;
   TREE_STATIC (init) = 1;
   /* Create a static variable to hold the jump table.  */
-  tmp = gfc_create_var (tmp, "jumptable");
+  tmp = gfc_create_var (type, "jumptable");
   TREE_CONSTANT (tmp) = 1;
   TREE_INVARIANT (tmp) = 1;
   TREE_STATIC (tmp) = 1;
@@ -990,7 +990,8 @@ gfc_trans_character_select (gfc_code *co
   init = tmp;
 
   /* Build an argument list for the library call */
-  init = build1 (ADDR_EXPR, pvoid_type_node, init);
+  init = build1 (ADDR_EXPR, build_pointer_type (type), init);
+  init = convert (pvoid_type_node, init);
   args = gfc_chainon_list (NULL_TREE, init);
 
   tmp = build_int_2 (n, 0);
@@ -1248,7 +1249,9 @@ gfc_do_allocate (tree bytesize, tree siz
     {
       tmpvar = gfc_create_var (build_pointer_type (type), "temp");
       TREE_ADDRESSABLE (tmpvar) = 1;
-      pointer = build1 (ADDR_EXPR, ppvoid_type_node, tmpvar);
+      pointer = build1 (ADDR_EXPR, build_pointer_type (TREE_TYPE (tmpvar)),
+			tmpvar);
+      pointer = convert (ppvoid_type_node, pointer);
 
       args = gfc_chainon_list (NULL_TREE, pointer);
       args = gfc_chainon_list (args, bytesize);
@@ -2953,7 +2956,9 @@ gfc_trans_allocate (gfc_code * code)
 	  tree val;
 
 	  val = gfc_create_var (ppvoid_type_node, "ptr");
-	  tmp = build1 (ADDR_EXPR, TREE_TYPE (val), se.expr);
+	  tmp = build_pointer_type (TREE_TYPE (se.expr));
+	  tmp = build1 (ADDR_EXPR, tmp, se.expr);
+	  tmp = convert (ppvoid_type_node, tmp);
 	  gfc_add_modify_expr (&se.pre, val, tmp);
 
 	  tmp = TYPE_SIZE_UNIT (TREE_TYPE (TREE_TYPE (se.expr)));
Index: gcc/java/class.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/java/class.c,v
retrieving revision 1.133.2.24
diff -u -p -r1.133.2.24 class.c
--- gcc/java/class.c	28 Oct 2003 14:58:19 -0000	1.133.2.24
+++ gcc/java/class.c	20 Nov 2003 23:20:10 -0000
@@ -819,8 +819,7 @@ build_indirect_class_ref (tree type)
   tree cl;
   index = alloc_class_constant (type);
   cl = build_ref_from_constant_pool (index); 
-  TREE_TYPE (cl) = promote_type (class_ptr_type);
-  return cl;
+  return convert (promote_type (class_ptr_type), cl);
 }
 
 /* Build a reference to the class TYPE.
Index: gcc/java/constants.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/java/constants.c,v
retrieving revision 1.20.2.6
diff -u -p -r1.20.2.6 constants.c
--- gcc/java/constants.c	7 May 2003 13:32:57 -0000	1.20.2.6
+++ gcc/java/constants.c	20 Nov 2003 23:20:10 -0000
@@ -371,29 +371,27 @@ alloc_class_constant (tree clas)
 				IDENTIFIER_LENGTH(class_name))));
 }
 
-/* Return a reference to the data array of the current constant pool. */
+/* Return the decl of the data array of the current constant pool. */
 
 static tree
 build_constant_data_ref (void)
 {
-  tree cpool_data_ref = NULL_TREE;
+  tree decl = TYPE_CPOOL_DATA_REF (current_class);
 
-  if (TYPE_CPOOL_DATA_REF (current_class))
-    cpool_data_ref = TYPE_CPOOL_DATA_REF (current_class);
-
-  if (cpool_data_ref == NULL_TREE)
+  if (decl == NULL_TREE)
     {
-      tree decl;
+      tree type;
       tree decl_name = mangled_classname ("_CD_", current_class);
-      decl = build_decl (VAR_DECL, decl_name,
-			 build_array_type (ptr_type_node,
-					   one_elt_array_domain_type));
+
+      type = build_array_type (ptr_type_node, NULL_TREE);
+      decl = build_decl (VAR_DECL, decl_name, type);
       TREE_STATIC (decl) = 1;
       make_decl_rtl (decl, NULL);
-      TYPE_CPOOL_DATA_REF (current_class) = cpool_data_ref
-	= build1 (ADDR_EXPR, ptr_type_node, decl);
+
+      TYPE_CPOOL_DATA_REF (current_class) = decl;
     }
-  return cpool_data_ref;
+
+  return decl;
 }
 
 /* Get the pointer value at the INDEX'th element of the constant pool. */
@@ -401,11 +399,9 @@ build_constant_data_ref (void)
 tree
 build_ref_from_constant_pool (int index)
 {
-  tree t = build_constant_data_ref ();
-  index *= int_size_in_bytes (ptr_type_node);
-  t = fold (build (PLUS_EXPR, ptr_type_node,
-                              t, build_int_2 (index, 0)));
-  return build1 (INDIRECT_REF, ptr_type_node, t);
+  tree d = build_constant_data_ref ();
+  tree i = build_int_2 (index, 0);
+  return build (ARRAY_REF, TREE_TYPE (TREE_TYPE (d)), d, i);
 }
 
 /* Build an initializer for the constants field of the current constant pool.
@@ -440,7 +436,7 @@ build_constants_constructor (void)
       tags_list = tree_cons (NULL_TREE, get_tag_node (0), tags_list);
       data_list = tree_cons (NULL_TREE, null_pointer_node, data_list);
   
-      data_decl = TREE_OPERAND (build_constant_data_ref (), 0);
+      data_decl = build_constant_data_ref ();
       TREE_TYPE (data_decl) = build_array_type (ptr_type_node, index_type), 
       DECL_INITIAL (data_decl) = build_constructor (TREE_TYPE (data_decl),
 						    data_list);
Index: gcc/java/expr.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/java/expr.c,v
retrieving revision 1.147.2.28
diff -u -p -r1.147.2.28 expr.c
--- gcc/java/expr.c	13 Nov 2003 02:39:02 -0000	1.147.2.28
+++ gcc/java/expr.c	20 Nov 2003 23:20:13 -0000
@@ -718,7 +718,10 @@ java_check_reference (tree expr, int che
 tree
 build_java_indirect_ref (tree type, tree expr, int check)
 {
-  return build1 (INDIRECT_REF, type, java_check_reference (expr, check));
+  tree t;
+  t = java_check_reference (expr, check);
+  t = convert (build_pointer_type (type), t);
+  return build1 (INDIRECT_REF, type, t);
 }
 
 /* Implement array indexing (either as l-value or r-value).
@@ -1809,15 +1812,17 @@ build_known_method_ref (tree method, tre
 	  || (!TREE_PUBLIC (method) && DECL_CONTEXT (method)))
 	{
 	  make_decl_rtl (method, NULL);
-	  func = build1 (ADDR_EXPR, method_ptr_type_node, method);
+	  func = build1 (ADDR_EXPR, build_pointer_type (TREE_TYPE (method)),
+			 method);
 	}
       else
 	{
 	  tree table_index = build_int_2 (get_symbol_table_index 
 					  (method, &atable_methods), 0);
-	  func = build (ARRAY_REF,  method_ptr_type_node, atable_decl, 
-			table_index);
+	  func = build (ARRAY_REF, TREE_TYPE (TREE_TYPE (atable_decl)),
+			atable_decl, table_index);
 	}
+      func = convert (method_ptr_type_node, func);
     }
   else
     {
@@ -2940,7 +2945,7 @@ java_push_constant_from_pool (JCF *jcf, 
       name = get_name_constant (jcf, JPOOL_USHORT1 (jcf, index));
       index = alloc_name_constant (CONSTANT_String, name);
       c = build_ref_from_constant_pool (index);
-      TREE_TYPE (c) = promote_type (string_type_node);
+      c = convert (promote_type (string_type_node), c);
     }
   else
     c = get_constant (jcf, index);
Index: gcc/java/parse.y
===================================================================
RCS file: /cvs/gcc/gcc/gcc/java/parse.y,v
retrieving revision 1.387.2.40
diff -u -p -r1.387.2.40 parse.y
--- gcc/java/parse.y	13 Nov 2003 02:39:02 -0000	1.387.2.40
+++ gcc/java/parse.y	20 Nov 2003 23:20:25 -0000
@@ -13966,9 +13966,15 @@ patch_string_cst (tree node)
       location = alloc_name_constant (CONSTANT_String, node);
       node = build_ref_from_constant_pool (location);
     }
-  TREE_TYPE (node) = string_ptr_type_node;
   TREE_CONSTANT (node) = 1;
   TREE_INVARIANT (node) = 1;
+
+  /* ??? Guessing that the class file code can't handle casts.  */
+  if (! flag_emit_class_files)
+    node = convert (string_ptr_type_node, node);
+  else
+    TREE_TYPE (node) = string_ptr_type_node;
+
   return node;
 }
 


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