Patchwork [gccgo] Remove code to convert address of array to slice

login
register
mail settings
Submitter Ian Taylor
Date Sept. 9, 2010, 9:59 p.m.
Message ID <mcreid2d1db.fsf@google.com>
Download mbox | patch
Permalink /patch/64338/
State New
Headers show

Comments

Ian Taylor - Sept. 9, 2010, 9:59 p.m.
The Go language no longer permits converting the address of an array to
a slice.  You must now slice it instead.  The gccgo compiler already
rejects this, but I didn't remove the code generation part.  This patch
does that.  Committed to gccgo branch.

Ian

Patch

diff -r 1ff612998528 go/expressions.cc
--- a/go/expressions.cc	Wed Sep 08 23:20:02 2010 -0700
+++ b/go/expressions.cc	Thu Sep 09 14:58:05 2010 -0700
@@ -233,109 +233,6 @@ 
     return Expression::convert_interface_to_type(context, lhs_type, rhs_type,
 						 rhs_tree, location);
   else if (lhs_type->is_open_array_type()
-	   && rhs_type->points_to() != NULL
-	   && rhs_type->points_to()->array_type() != NULL
-	   && !rhs_type->points_to()->is_open_array_type())
-    {
-      // Conversion from *[N]T to []T.
-      gcc_assert(TREE_CODE(lhs_type_tree) == RECORD_TYPE);
-
-      Array_type* rhs_at = rhs_type->points_to()->array_type();
-
-      VEC(constructor_elt,gc)* init = VEC_alloc(constructor_elt, gc, 3);
-
-      tree bad_index = NULL_TREE;
-      tree value_pointer;
-      bool is_constant;
-      if (!INDIRECT_REF_P(rhs_tree)
-	  || !TREE_CONSTANT(TREE_OPERAND(rhs_tree, 0))
-	  || !rhs_at->length()->is_constant())
-	{
-	  if (!DECL_P(rhs_tree))
-	    rhs_tree = save_expr(rhs_tree);
-	  bad_index = build2(EQ_EXPR, boolean_type_node, rhs_tree,
-			     fold_convert(TREE_TYPE(rhs_tree),
-					  null_pointer_node));
-	  value_pointer = rhs_tree;
-	  is_constant = false;
-	}
-      else
-	{
-	  tree decl;
-	  if (DECL_P(TREE_OPERAND(rhs_tree, 0)))
-	    value_pointer = rhs_tree;
-	  else
-	    {
-	      decl = build_decl(location, VAR_DECL, create_tmp_var_name("A"),
-				TREE_TYPE(TREE_TYPE(rhs_tree)));
-	      DECL_EXTERNAL(decl) = 0;
-	      TREE_PUBLIC(decl) = 0;
-	      TREE_STATIC(decl) = 1;
-	      DECL_ARTIFICIAL(decl) = 1;
-	      DECL_INITIAL(decl) = build_fold_indirect_ref(rhs_tree);
-	      rest_of_decl_compilation(decl, 1, 0);
-	      value_pointer = build_fold_addr_expr(decl);
-	    }
-	  is_constant = true;
-	}
-
-      constructor_elt* elt = VEC_quick_push(constructor_elt, init, NULL);
-      tree field = TYPE_FIELDS(lhs_type_tree);
-      gcc_assert(strcmp(IDENTIFIER_POINTER(DECL_NAME(field)),
-			"__values") == 0);
-      elt->index = field;
-      elt->value = value_pointer;
-      if (is_constant)
-	gcc_assert(TREE_CONSTANT(elt->value));
-
-      elt = VEC_quick_push(constructor_elt, init, NULL);
-      field = TREE_CHAIN(field);
-      gcc_assert(strcmp(IDENTIFIER_POINTER(DECL_NAME(field)),
-			"__count") == 0);
-      elt->index = field;
-      elt->value = fold_convert(TREE_TYPE(field),
-				rhs_at->length_tree(gogo, error_mark_node));
-      gcc_assert(elt->value != error_mark_node);
-      if (is_constant)
-	gcc_assert(TREE_CONSTANT(elt->value));
-
-      elt = VEC_quick_push(constructor_elt, init, NULL);
-      field = TREE_CHAIN(field);
-      gcc_assert(strcmp(IDENTIFIER_POINTER(DECL_NAME(field)),
-			"__capacity") == 0);
-      elt->index = field;
-      elt->value = fold_convert(TREE_TYPE(field),
-				rhs_at->capacity_tree(gogo, error_mark_node));
-      gcc_assert(elt->value != error_mark_node);
-      if (is_constant)
-	gcc_assert(TREE_CONSTANT(elt->value));
-
-      tree val = build_constructor(lhs_type_tree, init);
-      if (is_constant)
-	TREE_CONSTANT(val) = 1;
-
-      if (bad_index != NULL_TREE)
-	{
-	  gcc_assert(!is_constant);
-
-	  // FIXME: Duplicates Array_index_expression::do_get_tree.
-	  static tree bad_index_fndecl;
-	  tree crash = Gogo::call_builtin(&bad_index_fndecl,
-					  location,
-					  "__go_bad_index",
-					  0,
-					  void_type_node);
-	  TREE_NOTHROW(bad_index_fndecl) = 0;
-	  TREE_THIS_VOLATILE(bad_index_fndecl) = 1;
-	  val = build2(COMPOUND_EXPR, TREE_TYPE(val),
-		       build3(COND_EXPR, void_type_node,
-			      bad_index, crash, NULL_TREE),
-		       val);
-	}
-
-      return val;
-    }
-  else if (lhs_type->is_open_array_type()
 	   && rhs_type->is_nil_type())
     {
       // Assigning nil to an open array.