OSDN Git Service

compiler: Use backend interface for type sizes and alignments.
[pf3gnuchains/gcc-fork.git] / gcc / go / gofrontend / expressions.cc
index 180279e..337b949 100644 (file)
@@ -41,7 +41,7 @@ extern "C"
 // Class Expression.
 
 Expression::Expression(Expression_classification classification,
-                      source_location location)
+                      Location location)
   : classification_(classification), location_(location)
 {
 }
@@ -203,7 +203,7 @@ Expression::determine_type_no_context()
 tree
 Expression::convert_for_assignment(Translate_context* context, Type* lhs_type,
                                   Type* rhs_type, tree rhs_tree,
-                                  source_location location)
+                                  Location location)
 {
   if (lhs_type == rhs_type)
     return rhs_tree;
@@ -283,7 +283,7 @@ Expression::convert_for_assignment(Translate_context* context, Type* lhs_type,
           || INTEGRAL_TYPE_P(lhs_type_tree)
           || SCALAR_FLOAT_TYPE_P(lhs_type_tree)
           || COMPLEX_FLOAT_TYPE_P(lhs_type_tree))
-    return fold_convert_loc(location, lhs_type_tree, rhs_tree);
+    return fold_convert_loc(location.gcc_location(), lhs_type_tree, rhs_tree);
   else if (TREE_CODE(lhs_type_tree) == RECORD_TYPE
           && TREE_CODE(TREE_TYPE(rhs_tree)) == RECORD_TYPE)
     {
@@ -291,8 +291,8 @@ Expression::convert_for_assignment(Translate_context* context, Type* lhs_type,
       // gotten here.
       go_assert(int_size_in_bytes(lhs_type_tree)
                 == int_size_in_bytes(TREE_TYPE(rhs_tree)));
-      return fold_build1_loc(location, VIEW_CONVERT_EXPR, lhs_type_tree,
-                            rhs_tree);
+      return fold_build1_loc(location.gcc_location(), VIEW_CONVERT_EXPR,
+                             lhs_type_tree, rhs_tree);
     }
   else
     {
@@ -307,7 +307,7 @@ Expression::convert_for_assignment(Translate_context* context, Type* lhs_type,
 tree
 Expression::convert_type_to_interface(Translate_context* context,
                                      Type* lhs_type, Type* rhs_type,
-                                     tree rhs_tree, source_location location)
+                                     tree rhs_tree, Location location)
 {
   Gogo* gogo = context->gogo();
   Interface_type* lhs_interface_type = lhs_type->interface_type();
@@ -356,8 +356,8 @@ Expression::convert_type_to_interface(Translate_context* context,
        method_table =
          rhs_named_type->interface_method_table(gogo, lhs_interface_type,
                                                 is_pointer);
-      first_field_value = fold_convert_loc(location, const_ptr_type_node,
-                                          method_table);
+      first_field_value = fold_convert_loc(location.gcc_location(),
+                                           const_ptr_type_node, method_table);
     }
   if (first_field_value == error_mark_node)
     return error_mark_node;
@@ -371,7 +371,8 @@ Expression::convert_type_to_interface(Translate_context* context,
   go_assert(strcmp(IDENTIFIER_POINTER(DECL_NAME(field)),
                    (lhs_is_empty ? "__type_descriptor" : "__methods")) == 0);
   elt->index = field;
-  elt->value = fold_convert_loc(location, TREE_TYPE(field), first_field_value);
+  elt->value = fold_convert_loc(location.gcc_location(), TREE_TYPE(field),
+                                first_field_value);
 
   elt = VEC_quick_push(constructor_elt, init, NULL);
   field = DECL_CHAIN(field);
@@ -392,16 +393,17 @@ Expression::convert_type_to_interface(Translate_context* context,
   tree object_size = TYPE_SIZE_UNIT(TREE_TYPE(rhs_tree));
 
   tree space = gogo->allocate_memory(rhs_type, object_size, location);
-  space = fold_convert_loc(location, build_pointer_type(TREE_TYPE(rhs_tree)),
-                          space);
+  space = fold_convert_loc(location.gcc_location(),
+                           build_pointer_type(TREE_TYPE(rhs_tree)), space);
   space = save_expr(space);
 
-  tree ref = build_fold_indirect_ref_loc(location, space);
+  tree ref = build_fold_indirect_ref_loc(location.gcc_location(), space);
   TREE_THIS_NOTRAP(ref) = 1;
-  tree set = fold_build2_loc(location, MODIFY_EXPR, void_type_node,
-                            ref, rhs_tree);
+  tree set = fold_build2_loc(location.gcc_location(), MODIFY_EXPR,
+                             void_type_node, ref, rhs_tree);
 
-  elt->value = fold_convert_loc(location, TREE_TYPE(field), space);
+  elt->value = fold_convert_loc(location.gcc_location(), TREE_TYPE(field),
+                                space);
 
   return build2(COMPOUND_EXPR, lhs_type_tree, set,
                build_constructor(lhs_type_tree, init));
@@ -414,7 +416,7 @@ Expression::convert_type_to_interface(Translate_context* context,
 tree
 Expression::get_interface_type_descriptor(Translate_context*,
                                          Type* rhs_type, tree rhs_tree,
-                                         source_location location)
+                                         Location location)
 {
   tree rhs_type_tree = TREE_TYPE(rhs_tree);
   go_assert(TREE_CODE(rhs_type_tree) == RECORD_TYPE);
@@ -432,18 +434,20 @@ Expression::get_interface_type_descriptor(Translate_context*,
             == 0);
   go_assert(POINTER_TYPE_P(TREE_TYPE(v)));
   v = save_expr(v);
-  tree v1 = build_fold_indirect_ref_loc(location, v);
+  tree v1 = build_fold_indirect_ref_loc(location.gcc_location(), v);
   go_assert(TREE_CODE(TREE_TYPE(v1)) == RECORD_TYPE);
   tree f = TYPE_FIELDS(TREE_TYPE(v1));
   go_assert(strcmp(IDENTIFIER_POINTER(DECL_NAME(f)), "__type_descriptor")
             == 0);
   v1 = build3(COMPONENT_REF, TREE_TYPE(f), v1, f, NULL_TREE);
 
-  tree eq = fold_build2_loc(location, EQ_EXPR, boolean_type_node, v,
-                           fold_convert_loc(location, TREE_TYPE(v),
-                                            null_pointer_node));
-  tree n = fold_convert_loc(location, TREE_TYPE(v1), null_pointer_node);
-  return fold_build3_loc(location, COND_EXPR, TREE_TYPE(v1),
+  tree eq = fold_build2_loc(location.gcc_location(), EQ_EXPR, boolean_type_node,
+                            v, fold_convert_loc(location.gcc_location(),
+                                                TREE_TYPE(v),
+                                                null_pointer_node));
+  tree n = fold_convert_loc(location.gcc_location(), TREE_TYPE(v1),
+                            null_pointer_node);
+  return fold_build3_loc(location.gcc_location(), COND_EXPR, TREE_TYPE(v1),
                         eq, n, v1);
 }
 
@@ -454,7 +458,7 @@ tree
 Expression::convert_interface_to_interface(Translate_context* context,
                                           Type *lhs_type, Type *rhs_type,
                                           tree rhs_tree, bool for_type_guard,
-                                          source_location location)
+                                          Location location)
 {
   Gogo* gogo = context->gogo();
   Interface_type* lhs_interface_type = lhs_type->interface_type();
@@ -509,7 +513,8 @@ Expression::convert_interface_to_interface(Translate_context* context,
        return error_mark_node;
       // This will panic if the interface conversion fails.
       TREE_NOTHROW(assert_interface_decl) = 0;
-      elt->value = fold_convert_loc(location, TREE_TYPE(field), call);
+      elt->value = fold_convert_loc(location.gcc_location(), TREE_TYPE(field),
+                                    call);
     }
   else if (lhs_is_empty)
     {
@@ -542,7 +547,8 @@ Expression::convert_interface_to_interface(Translate_context* context,
        return error_mark_node;
       // This will panic if the interface conversion fails.
       TREE_NOTHROW(convert_interface_decl) = 0;
-      elt->value = fold_convert_loc(location, TREE_TYPE(field), call);
+      elt->value = fold_convert_loc(location.gcc_location(), TREE_TYPE(field),
+                                    call);
     }
 
   // The second field is simply the object pointer.
@@ -568,7 +574,7 @@ Expression::convert_interface_to_interface(Translate_context* context,
 tree
 Expression::convert_interface_to_type(Translate_context* context,
                                      Type *lhs_type, Type* rhs_type,
-                                     tree rhs_tree, source_location location)
+                                     tree rhs_tree, Location location)
 {
   Gogo* gogo = context->gogo();
   tree rhs_type_tree = TREE_TYPE(rhs_tree);
@@ -621,12 +627,13 @@ Expression::convert_interface_to_type(Translate_context* context,
   // Otherwise it points to the value.
   if (lhs_type->points_to() == NULL)
     {
-      val = fold_convert_loc(location, build_pointer_type(lhs_type_tree), val);
-      val = build_fold_indirect_ref_loc(location, val);
+      val = fold_convert_loc(location.gcc_location(),
+                             build_pointer_type(lhs_type_tree), val);
+      val = build_fold_indirect_ref_loc(location.gcc_location(), val);
     }
 
   return build2(COMPOUND_EXPR, lhs_type_tree, call,
-               fold_convert_loc(location, lhs_type_tree, val));
+               fold_convert_loc(location.gcc_location(), lhs_type_tree, val));
 }
 
 // Convert an expression to a tree.  This is implemented by the child
@@ -748,14 +755,14 @@ Expression::complex_constant_tree(mpfr_t real, mpfr_t imag, tree type)
 
 tree
 Expression::check_bounds(tree val, tree bound_type, tree sofar,
-                        source_location loc)
+                        Location loc)
 {
   tree val_type = TREE_TYPE(val);
   tree ret = NULL_TREE;
 
   if (!TYPE_UNSIGNED(val_type))
     {
-      ret = fold_build2_loc(loc, LT_EXPR, boolean_type_node, val,
+      ret = fold_build2_loc(loc.gcc_location(), LT_EXPR, boolean_type_node, val,
                            build_int_cst(val_type, 0));
       if (ret == boolean_false_node)
        ret = NULL_TREE;
@@ -770,15 +777,16 @@ Expression::check_bounds(tree val, tree bound_type, tree sofar,
          && !TYPE_UNSIGNED(bound_type)))
     {
       tree max = TYPE_MAX_VALUE(bound_type);
-      tree big = fold_build2_loc(loc, GT_EXPR, boolean_type_node, val,
-                                fold_convert_loc(loc, val_type, max));
+      tree big = fold_build2_loc(loc.gcc_location(), GT_EXPR, boolean_type_node,
+                                 val, fold_convert_loc(loc.gcc_location(),
+                                                       val_type, max));
       if (big == boolean_false_node)
        ;
       else if (ret == NULL_TREE)
        ret = big;
       else
-       ret = fold_build2_loc(loc, TRUTH_OR_EXPR, boolean_type_node,
-                             ret, big);
+       ret = fold_build2_loc(loc.gcc_location(), TRUTH_OR_EXPR,
+                              boolean_type_node, ret, big);
     }
 
   if (ret == NULL_TREE)
@@ -786,7 +794,7 @@ Expression::check_bounds(tree val, tree bound_type, tree sofar,
   else if (sofar == NULL_TREE)
     return ret;
   else
-    return fold_build2_loc(loc, TRUTH_OR_EXPR, boolean_type_node,
+    return fold_build2_loc(loc.gcc_location(), TRUTH_OR_EXPR, boolean_type_node,
                           sofar, ret);
 }
 
@@ -801,7 +809,7 @@ Expression::dump_expression(Ast_dump_context* ast_dump_context) const
 class Error_expression : public Expression
 {
  public:
-  Error_expression(source_location location)
+  Error_expression(Location location)
     : Expression(EXPRESSION_ERROR, location)
   { }
 
@@ -869,7 +877,7 @@ Error_expression::do_dump_expression(Ast_dump_context* ast_dump_context) const
 }
 
 Expression*
-Expression::make_error(source_location location)
+Expression::make_error(Location location)
 {
   return new Error_expression(location);
 }
@@ -881,7 +889,7 @@ class
 Type_expression : public Expression
 {
  public:
-  Type_expression(Type* type, source_location location)
+  Type_expression(Type* type, Location location)
     : Expression(EXPRESSION_TYPE, location),
       type_(type)
   { }
@@ -925,7 +933,7 @@ Type_expression::do_dump_expression(Ast_dump_context* ast_dump_context) const
 }
 
 Expression*
-Expression::make_type(Type* type, source_location location)
+Expression::make_type(Type* type, Location location)
 {
   return new Type_expression(type, location);
 }
@@ -1037,7 +1045,7 @@ Var_expression::do_get_tree(Translate_context* context)
     go_unreachable();
   if (is_in_heap)
     {
-      ret = build_fold_indirect_ref_loc(this->location(), ret);
+      ret = build_fold_indirect_ref_loc(this->location().gcc_location(), ret);
       TREE_THIS_NOTRAP(ret) = 1;
     }
   return ret;
@@ -1054,7 +1062,7 @@ Var_expression::do_dump_expression(Ast_dump_context* ast_dump_context) const
 // Make a reference to a variable in an expression.
 
 Expression*
-Expression::make_var_reference(Named_object* var, source_location location)
+Expression::make_var_reference(Named_object* var, Location location)
 {
   if (var->is_sink())
     return Expression::make_sink(location);
@@ -1104,7 +1112,7 @@ Temporary_reference_expression::do_get_tree(Translate_context* context)
     {
       Btype* type_btype = this->type()->base()->get_backend(context->gogo());
       tree type_tree = type_to_tree(type_btype);
-      ret = fold_convert_loc(this->location(), type_tree, ret);
+      ret = fold_convert_loc(this->location().gcc_location(), type_tree, ret);
     }
   return ret;
 }
@@ -1122,17 +1130,74 @@ Temporary_reference_expression::do_dump_expression(
 
 Temporary_reference_expression*
 Expression::make_temporary_reference(Temporary_statement* statement,
-                                    source_location location)
+                                    Location location)
 {
   return new Temporary_reference_expression(statement, location);
 }
 
+// Class Set_and_use_temporary_expression.
+
+// Return the type.
+
+Type*
+Set_and_use_temporary_expression::do_type()
+{
+  return this->statement_->type();
+}
+
+// Take the address.
+
+void
+Set_and_use_temporary_expression::do_address_taken(bool)
+{
+  this->statement_->set_is_address_taken();
+}
+
+// Return the backend representation.
+
+tree
+Set_and_use_temporary_expression::do_get_tree(Translate_context* context)
+{
+  Bvariable* bvar = this->statement_->get_backend_variable(context);
+  tree var_tree = var_to_tree(bvar);
+  tree expr_tree = this->expr_->get_tree(context);
+  if (var_tree == error_mark_node || expr_tree == error_mark_node)
+    return error_mark_node;
+  Location loc = this->location();
+  return build2_loc(loc.gcc_location(), COMPOUND_EXPR, TREE_TYPE(var_tree),
+                   build2_loc(loc.gcc_location(), MODIFY_EXPR, void_type_node,
+                              var_tree, expr_tree),
+                   var_tree);
+}
+
+// Dump.
+
+void
+Set_and_use_temporary_expression::do_dump_expression(
+    Ast_dump_context* ast_dump_context) const
+{
+  ast_dump_context->ostream() << '(';
+  ast_dump_context->dump_temp_variable_name(this->statement_);
+  ast_dump_context->ostream() << " = ";
+  this->expr_->dump_expression(ast_dump_context);
+  ast_dump_context->ostream() << ')';
+}
+
+// Make a set-and-use temporary.
+
+Set_and_use_temporary_expression*
+Expression::make_set_and_use_temporary(Temporary_statement* statement,
+                                      Expression* expr, Location location)
+{
+  return new Set_and_use_temporary_expression(statement, expr, location);
+}
+
 // A sink expression--a use of the blank identifier _.
 
 class Sink_expression : public Expression
 {
  public:
-  Sink_expression(source_location location)
+  Sink_expression(Location location)
     : Expression(EXPRESSION_SINK, location),
       type_(NULL), var_(NULL_TREE)
   { }
@@ -1210,7 +1275,7 @@ Sink_expression::do_dump_expression(Ast_dump_context* ast_dump_context) const
 // Make a sink expression.
 
 Expression*
-Expression::make_sink(source_location location)
+Expression::make_sink(Location location)
 {
   return new Sink_expression(location);
 }
@@ -1285,7 +1350,7 @@ Func_expression::get_tree_without_closure(Gogo* gogo)
   if (fndecl == error_mark_node)
     return error_mark_node;
 
-  return build_fold_addr_expr_loc(this->location(), fndecl);
+  return build_fold_addr_expr_loc(this->location().gcc_location(), fndecl);
 }
 
 // Get the tree for a function expression.  This is used when we take
@@ -1357,7 +1422,7 @@ Func_expression::do_dump_expression(Ast_dump_context* ast_dump_context) const
 
 Expression*
 Expression::make_func_reference(Named_object* function, Expression* closure,
-                               source_location location)
+                               Location location)
 {
   return new Func_expression(function, closure, location);
 }
@@ -1377,7 +1442,7 @@ Unknown_expression::name() const
 Expression*
 Unknown_expression::do_lower(Gogo*, Named_object*, Statement_inserter*, int)
 {
-  source_location location = this->location();
+  Location location = this->location();
   Named_object* no = this->named_object_;
   Named_object* real;
   if (!no->is_unknown())
@@ -1433,7 +1498,7 @@ Unknown_expression::do_dump_expression(Ast_dump_context* ast_dump_context) const
 // Make a reference to an unknown name.
 
 Expression*
-Expression::make_unknown_reference(Named_object* no, source_location location)
+Expression::make_unknown_reference(Named_object* no, Location location)
 {
   return new Unknown_expression(no, location);
 }
@@ -1443,7 +1508,7 @@ Expression::make_unknown_reference(Named_object* no, source_location location)
 class Boolean_expression : public Expression
 {
  public:
-  Boolean_expression(bool val, source_location location)
+  Boolean_expression(bool val, Location location)
     : Expression(EXPRESSION_BOOLEAN, location),
       val_(val), type_(NULL)
   { }
@@ -1528,7 +1593,7 @@ Boolean_expression::do_import(Import* imp)
 // Make a boolean expression.
 
 Expression*
-Expression::make_boolean(bool val, source_location location)
+Expression::make_boolean(bool val, Location location)
 {
   return new Boolean_expression(val, location);
 }
@@ -1665,7 +1730,7 @@ String_expression::do_dump_expression(Ast_dump_context* ast_dump_context) const
 // Make a string expression.
 
 Expression*
-Expression::make_string(const std::string& val, source_location location)
+Expression::make_string(const std::string& val, Location location)
 {
   return new String_expression(val, location);
 }
@@ -1675,7 +1740,7 @@ Expression::make_string(const std::string& val, source_location location)
 class Integer_expression : public Expression
 {
  public:
-  Integer_expression(const mpz_t* val, Type* type, source_location location)
+  Integer_expression(const mpz_t* val, Type* type, Location location)
     : Expression(EXPRESSION_INTEGER, location),
       type_(type)
   { mpz_init_set(this->val_, *val); }
@@ -1685,7 +1750,7 @@ class Integer_expression : public Expression
 
   // Return whether VAL fits in the type.
   static bool
-  check_constant(mpz_t val, Type*, source_location);
+  check_constant(mpz_t val, Type*, Location);
 
   // Write VAL to string dump.
   static void
@@ -1778,7 +1843,7 @@ Integer_expression::do_determine_type(const Type_context* context)
 
 bool
 Integer_expression::check_constant(mpz_t val, Type* type,
-                                  source_location location)
+                                  Location location)
 {
   if (type == NULL)
     return true;
@@ -1985,7 +2050,7 @@ Integer_expression::do_dump_expression(Ast_dump_context* ast_dump_context) const
 
 Expression*
 Expression::make_integer(const mpz_t* val, Type* type,
-                        source_location location)
+                        Location location)
 {
   return new Integer_expression(val, type, location);
 }
@@ -1995,7 +2060,7 @@ Expression::make_integer(const mpz_t* val, Type* type,
 class Float_expression : public Expression
 {
  public:
-  Float_expression(const mpfr_t* val, Type* type, source_location location)
+  Float_expression(const mpfr_t* val, Type* type, Location location)
     : Expression(EXPRESSION_FLOAT, location),
       type_(type)
   {
@@ -2008,7 +2073,7 @@ class Float_expression : public Expression
 
   // Return whether VAL fits in the type.
   static bool
-  check_constant(mpfr_t val, Type*, source_location);
+  check_constant(mpfr_t val, Type*, Location);
 
   // Write VAL to export data.
   static void
@@ -2111,7 +2176,7 @@ Float_expression::do_determine_type(const Type_context* context)
 
 bool
 Float_expression::check_constant(mpfr_t val, Type* type,
-                                source_location location)
+                                Location location)
 {
   if (type == NULL)
     return true;
@@ -2237,7 +2302,7 @@ Float_expression::do_dump_expression(Ast_dump_context* ast_dump_context) const
 // Make a float expression.
 
 Expression*
-Expression::make_float(const mpfr_t* val, Type* type, source_location location)
+Expression::make_float(const mpfr_t* val, Type* type, Location location)
 {
   return new Float_expression(val, type, location);
 }
@@ -2248,7 +2313,7 @@ class Complex_expression : public Expression
 {
  public:
   Complex_expression(const mpfr_t* real, const mpfr_t* imag, Type* type,
-                    source_location location)
+                    Location location)
     : Expression(EXPRESSION_COMPLEX, location),
       type_(type)
   {
@@ -2262,7 +2327,7 @@ class Complex_expression : public Expression
 
   // Return whether REAL/IMAG fits in the type.
   static bool
-  check_constant(mpfr_t real, mpfr_t imag, Type*, source_location);
+  check_constant(mpfr_t real, mpfr_t imag, Type*, Location);
 
   // Write REAL/IMAG to string dump.
   static void
@@ -2373,7 +2438,7 @@ Complex_expression::do_determine_type(const Type_context* context)
 
 bool
 Complex_expression::check_constant(mpfr_t real, mpfr_t imag, Type* type,
-                                  source_location location)
+                                  Location location)
 {
   if (type == NULL)
     return true;
@@ -2489,7 +2554,7 @@ Complex_expression::do_dump_expression(Ast_dump_context* ast_dump_context) const
 
 Expression*
 Expression::make_complex(const mpfr_t* real, const mpfr_t* imag, Type* type,
-                        source_location location)
+                        Location location)
 {
   return new Complex_expression(real, imag, type, location);
 }
@@ -2525,7 +2590,7 @@ class Find_named_object : public Traverse
 class Const_expression : public Expression
 {
  public:
-  Const_expression(Named_object* constant, source_location location)
+  Const_expression(Named_object* constant, Location location)
     : Expression(EXPRESSION_CONST_REFERENCE, location),
       constant_(constant), type_(NULL), seen_(false)
   { }
@@ -2982,7 +3047,7 @@ Const_expression::do_dump_expression(Ast_dump_context* ast_dump_context) const
 
 Expression*
 Expression::make_const_reference(Named_object* constant,
-                                source_location location)
+                                Location location)
 {
   return new Const_expression(constant, location);
 }
@@ -3028,7 +3093,7 @@ Find_named_object::expression(Expression** pexpr)
 class Nil_expression : public Expression
 {
  public:
-  Nil_expression(source_location location)
+  Nil_expression(Location location)
     : Expression(EXPRESSION_NIL, location)
   { }
 
@@ -3077,7 +3142,7 @@ Nil_expression::do_import(Import* imp)
 // Make a nil expression.
 
 Expression*
-Expression::make_nil(source_location location)
+Expression::make_nil(Location location)
 {
   return new Nil_expression(location);
 }
@@ -3090,7 +3155,7 @@ Expression::make_nil(source_location location)
 class Iota_expression : public Parser_expression
 {
  public:
-  Iota_expression(source_location location)
+  Iota_expression(Location location)
     : Parser_expression(EXPRESSION_IOTA, location)
   { }
 
@@ -3115,7 +3180,7 @@ class Iota_expression : public Parser_expression
 Expression*
 Expression::make_iota()
 {
-  static Iota_expression iota_expression(UNKNOWN_LOCATION);
+  static Iota_expression iota_expression(Linemap::unknown_location());
   return &iota_expression;
 }
 
@@ -3125,7 +3190,7 @@ class Type_conversion_expression : public Expression
 {
  public:
   Type_conversion_expression(Type* type, Expression* expr,
-                            source_location location)
+                            Location location)
     : Expression(EXPRESSION_CONVERSION, location),
       type_(type), expr_(expr), may_convert_function_types_(false)
   { }
@@ -3234,7 +3299,7 @@ Type_conversion_expression::do_lower(Gogo*, Named_object*,
 {
   Type* type = this->type_;
   Expression* val = this->expr_;
-  source_location location = this->location();
+  Location location = this->location();
 
   if (type->integer_type() != NULL)
     {
@@ -3314,7 +3379,7 @@ Type_conversion_expression::do_lower(Gogo*, Named_object*,
       mpfr_clear(imag);
     }
 
-  if (type->is_slice_type() && type->named_type() == NULL)
+  if (type->is_slice_type())
     {
       Type* element_type = type->array_type()->element_type()->forwarded();
       bool is_byte = element_type == Type::lookup_integer_type("uint8");
@@ -3613,26 +3678,18 @@ Type_conversion_expression::do_get_tree(Translate_context* context)
                               integer_type_node,
                               fold_convert(integer_type_node, expr_tree));
     }
-  else if (type->is_string_type()
-          && (expr_type->array_type() != NULL
-              || (expr_type->points_to() != NULL
-                  && expr_type->points_to()->array_type() != NULL)))
+  else if (type->is_string_type() && expr_type->is_slice_type())
     {
-      Type* t = expr_type;
-      if (t->points_to() != NULL)
-       {
-         t = t->points_to();
-         expr_tree = build_fold_indirect_ref(expr_tree);
-       }
       if (!DECL_P(expr_tree))
        expr_tree = save_expr(expr_tree);
-      Array_type* a = t->array_type();
+      Array_type* a = expr_type->array_type();
       Type* e = a->element_type()->forwarded();
       go_assert(e->integer_type() != NULL);
       tree valptr = fold_convert(const_ptr_type_node,
                                 a->value_pointer_tree(gogo, expr_tree));
       tree len = a->length_tree(gogo, expr_tree);
-      len = fold_convert_loc(this->location(), integer_type_node, len);
+      len = fold_convert_loc(this->location().gcc_location(), integer_type_node,
+                             len);
       if (e->integer_type()->is_unsigned()
          && e->integer_type()->bits() == 8)
        {
@@ -3669,7 +3726,7 @@ Type_conversion_expression::do_get_tree(Translate_context* context)
       if (e->integer_type()->is_unsigned()
          && e->integer_type()->bits() == 8)
        {
-         static tree string_to_byte_array_fndecl;
+         tree string_to_byte_array_fndecl = NULL_TREE;
          ret = Gogo::call_builtin(&string_to_byte_array_fndecl,
                                   this->location(),
                                   "__go_string_to_byte_array",
@@ -3681,7 +3738,7 @@ Type_conversion_expression::do_get_tree(Translate_context* context)
       else
        {
          go_assert(e == Type::lookup_integer_type("int"));
-         static tree string_to_int_array_fndecl;
+         tree string_to_int_array_fndecl = NULL_TREE;
          ret = Gogo::call_builtin(&string_to_int_array_fndecl,
                                   this->location(),
                                   "__go_string_to_int_array",
@@ -3702,7 +3759,8 @@ Type_conversion_expression::do_get_tree(Translate_context* context)
   else if (this->may_convert_function_types_
           && type->function_type() != NULL
           && expr_type->function_type() != NULL)
-    ret = fold_convert_loc(this->location(), type_tree, expr_tree);
+    ret = fold_convert_loc(this->location().gcc_location(), type_tree,
+                           expr_tree);
   else
     ret = Expression::convert_for_assignment(context, type, expr_type,
                                             expr_tree, this->location());
@@ -3750,7 +3808,7 @@ Type_conversion_expression::do_dump_expression(
 // Make a type cast expression.
 
 Expression*
-Expression::make_cast(Type* type, Expression* val, source_location location)
+Expression::make_cast(Type* type, Expression* val, Location location)
 {
   if (type->is_error_type() || val->is_error_expression())
     return Expression::make_error(location);
@@ -3763,7 +3821,7 @@ class Unsafe_type_conversion_expression : public Expression
 {
  public:
   Unsafe_type_conversion_expression(Type* type, Expression* expr,
-                                   source_location location)
+                                   Location location)
     : Expression(EXPRESSION_UNSAFE_CONVERSION, location),
       type_(type), expr_(expr)
   { }
@@ -3827,7 +3885,7 @@ Unsafe_type_conversion_expression::do_get_tree(Translate_context* context)
   if (type_tree == error_mark_node || expr_tree == error_mark_node)
     return error_mark_node;
 
-  source_location loc = this->location();
+  Location loc = this->location();
 
   bool use_view_convert = false;
   if (t->is_slice_type())
@@ -3873,9 +3931,10 @@ Unsafe_type_conversion_expression::do_get_tree(Translate_context* context)
     go_unreachable();
 
   if (use_view_convert)
-    return fold_build1_loc(loc, VIEW_CONVERT_EXPR, type_tree, expr_tree);
+    return fold_build1_loc(loc.gcc_location(), VIEW_CONVERT_EXPR, type_tree,
+                           expr_tree);
   else
-    return fold_convert_loc(loc, type_tree, expr_tree);
+    return fold_convert_loc(loc.gcc_location(), type_tree, expr_tree);
 }
 
 // Dump ast representation for an unsafe type conversion expression.
@@ -3894,7 +3953,7 @@ Unsafe_type_conversion_expression::do_dump_expression(
 
 Expression*
 Expression::make_unsafe_cast(Type* type, Expression* expr,
-                            source_location location)
+                            Location location)
 {
   return new Unsafe_type_conversion_expression(type, expr, location);
 }
@@ -3904,7 +3963,7 @@ Expression::make_unsafe_cast(Type* type, Expression* expr,
 class Unary_expression : public Expression
 {
  public:
-  Unary_expression(Operator op, Expression* expr, source_location location)
+  Unary_expression(Operator op, Expression* expr, Location location)
     : Expression(EXPRESSION_UNARY, location),
       op_(op), escapes_(true), create_temp_(false), expr_(expr)
   { }
@@ -3940,7 +3999,7 @@ class Unary_expression : public Expression
   // could be done, false if not.
   static bool
   eval_integer(Operator op, Type* utype, mpz_t uval, mpz_t val,
-              source_location);
+              Location);
 
   // Apply unary opcode OP to UVAL, setting VAL.  Return true if this
   // could be done, false if not.
@@ -4029,7 +4088,7 @@ class Unary_expression : public Expression
 Expression*
 Unary_expression::do_lower(Gogo*, Named_object*, Statement_inserter*, int)
 {
-  source_location loc = this->location();
+  Location loc = this->location();
   Operator op = this->op_;
   Expression* expr = this->expr_;
 
@@ -4170,7 +4229,7 @@ Unary_expression::do_is_constant() const
 
 bool
 Unary_expression::eval_integer(Operator op, Type* utype, mpz_t uval, mpz_t val,
-                              source_location location)
+                              Location location)
 {
   switch (op)
     {
@@ -4466,11 +4525,38 @@ Unary_expression::do_check_types(Gogo*)
 tree
 Unary_expression::do_get_tree(Translate_context* context)
 {
+  Location loc = this->location();
+
+  // Taking the address of a set-and-use-temporary expression requires
+  // setting the temporary and then taking the address.
+  if (this->op_ == OPERATOR_AND)
+    {
+      Set_and_use_temporary_expression* sut =
+       this->expr_->set_and_use_temporary_expression();
+      if (sut != NULL)
+       {
+         Temporary_statement* temp = sut->temporary();
+         Bvariable* bvar = temp->get_backend_variable(context);
+         tree var_tree = var_to_tree(bvar);
+         Expression* val = sut->expression();
+         tree val_tree = val->get_tree(context);
+         if (var_tree == error_mark_node || val_tree == error_mark_node)
+           return error_mark_node;
+         tree addr_tree = build_fold_addr_expr_loc(loc.gcc_location(),
+                                                   var_tree);
+         return build2_loc(loc.gcc_location(), COMPOUND_EXPR,
+                           TREE_TYPE(addr_tree),
+                           build2_loc(sut->location().gcc_location(),
+                                      MODIFY_EXPR, void_type_node,
+                                      var_tree, val_tree),
+                           addr_tree);
+       }
+    }
+
   tree expr = this->expr_->get_tree(context);
   if (expr == error_mark_node)
     return error_mark_node;
 
-  source_location loc = this->location();
   switch (this->op_)
     {
     case OPERATOR_PLUS:
@@ -4482,7 +4568,7 @@ Unary_expression::do_get_tree(Translate_context* context)
        tree compute_type = excess_precision_type(type);
        if (compute_type != NULL_TREE)
          expr = ::convert(compute_type, expr);
-       tree ret = fold_build1_loc(loc, NEGATE_EXPR,
+       tree ret = fold_build1_loc(loc.gcc_location(), NEGATE_EXPR,
                                   (compute_type != NULL_TREE
                                    ? compute_type
                                    : type),
@@ -4494,13 +4580,15 @@ Unary_expression::do_get_tree(Translate_context* context)
 
     case OPERATOR_NOT:
       if (TREE_CODE(TREE_TYPE(expr)) == BOOLEAN_TYPE)
-       return fold_build1_loc(loc, TRUTH_NOT_EXPR, TREE_TYPE(expr), expr);
+       return fold_build1_loc(loc.gcc_location(), TRUTH_NOT_EXPR,
+                               TREE_TYPE(expr), expr);
       else
-       return fold_build2_loc(loc, NE_EXPR, boolean_type_node, expr,
-                              build_int_cst(TREE_TYPE(expr), 0));
+       return fold_build2_loc(loc.gcc_location(), NE_EXPR, boolean_type_node,
+                               expr, build_int_cst(TREE_TYPE(expr), 0));
 
     case OPERATOR_XOR:
-      return fold_build1_loc(loc, BIT_NOT_EXPR, TREE_TYPE(expr), expr);
+      return fold_build1_loc(loc.gcc_location(), BIT_NOT_EXPR, TREE_TYPE(expr),
+                             expr);
 
     case OPERATOR_AND:
       if (!this->create_temp_)
@@ -4516,7 +4604,7 @@ Unary_expression::do_get_tree(Translate_context* context)
       // Build a decl for a constant constructor.
       if (TREE_CODE(expr) == CONSTRUCTOR && TREE_CONSTANT(expr))
        {
-         tree decl = build_decl(this->location(), VAR_DECL,
+         tree decl = build_decl(this->location().gcc_location(), VAR_DECL,
                                 create_tmp_var_name("C"), TREE_TYPE(expr));
          DECL_EXTERNAL(decl) = 0;
          TREE_PUBLIC(decl) = 0;
@@ -4540,13 +4628,14 @@ Unary_expression::do_get_tree(Translate_context* context)
          DECL_IGNORED_P(tmp) = 1;
          DECL_INITIAL(tmp) = expr;
          TREE_ADDRESSABLE(tmp) = 1;
-         return build2_loc(loc, COMPOUND_EXPR,
+         return build2_loc(loc.gcc_location(), COMPOUND_EXPR,
                            build_pointer_type(TREE_TYPE(expr)),
-                           build1_loc(loc, DECL_EXPR, void_type_node, tmp),
-                           build_fold_addr_expr_loc(loc, tmp));
+                           build1_loc(loc.gcc_location(), DECL_EXPR,
+                                       void_type_node, tmp),
+                           build_fold_addr_expr_loc(loc.gcc_location(), tmp));
        }
 
-      return build_fold_addr_expr_loc(loc, expr);
+      return build_fold_addr_expr_loc(loc.gcc_location(), expr);
 
     case OPERATOR_MULT:
       {
@@ -4561,15 +4650,18 @@ Unary_expression::do_get_tree(Translate_context* context)
          {
            if (!DECL_P(expr))
              expr = save_expr(expr);
-           tree compare = fold_build2_loc(loc, EQ_EXPR, boolean_type_node,
+           tree compare = fold_build2_loc(loc.gcc_location(), EQ_EXPR,
+                                           boolean_type_node,
                                           expr,
                                           fold_convert(TREE_TYPE(expr),
                                                        null_pointer_node));
            tree crash = Gogo::runtime_error(RUNTIME_ERROR_NIL_DEREFERENCE,
                                             loc);
-           expr = fold_build2_loc(loc, COMPOUND_EXPR, TREE_TYPE(expr),
-                                  build3(COND_EXPR, void_type_node,
-                                         compare, crash, NULL_TREE),
+           expr = fold_build2_loc(loc.gcc_location(), COMPOUND_EXPR,
+                                   TREE_TYPE(expr), build3(COND_EXPR,
+                                                           void_type_node,
+                                                           compare, crash,
+                                                           NULL_TREE),
                                   expr);
          }
 
@@ -4579,10 +4671,11 @@ Unary_expression::do_get_tree(Translate_context* context)
          {
            Type* pt = this->expr_->type()->points_to();
            tree ind = type_to_tree(pt->get_backend(context->gogo()));
-           expr = fold_convert_loc(loc, build_pointer_type(ind), expr);
+           expr = fold_convert_loc(loc.gcc_location(),
+                                    build_pointer_type(ind), expr);
          }
 
-       return build_fold_indirect_ref_loc(loc, expr);
+       return build_fold_indirect_ref_loc(loc.gcc_location(), expr);
       }
 
     default:
@@ -4659,7 +4752,7 @@ Unary_expression::do_dump_expression(Ast_dump_context* ast_dump_context) const
 // Make a unary expression.
 
 Expression*
-Expression::make_unary(Operator op, Expression* expr, source_location location)
+Expression::make_unary(Operator op, Expression* expr, Location location)
 {
   return new Unary_expression(op, expr, location);
 }
@@ -4807,7 +4900,7 @@ Binary_expression::compare_complex(Operator op, Type* type,
 bool
 Binary_expression::eval_integer(Operator op, Type* left_type, mpz_t left_val,
                                Type* right_type, mpz_t right_val,
-                               source_location location, mpz_t val)
+                               Location location, mpz_t val)
 {
   bool is_shift_op = false;
   switch (op)
@@ -4947,7 +5040,7 @@ Binary_expression::eval_integer(Operator op, Type* left_type, mpz_t left_val,
 bool
 Binary_expression::eval_float(Operator op, Type* left_type, mpfr_t left_val,
                              Type* right_type, mpfr_t right_val,
-                             mpfr_t val, source_location location)
+                             mpfr_t val, Location location)
 {
   switch (op)
     {
@@ -5030,7 +5123,7 @@ Binary_expression::eval_complex(Operator op, Type* left_type,
                                Type *right_type,
                                mpfr_t right_real, mpfr_t right_imag,
                                mpfr_t real, mpfr_t imag,
-                               source_location location)
+                               Location location)
 {
   switch (op)
     {
@@ -5389,9 +5482,10 @@ Binary_expression::eval_complex(Operator op, Type* left_type,
 // constants.
 
 Expression*
-Binary_expression::do_lower(Gogo*, Named_object*, Statement_inserter*, int)
+Binary_expression::do_lower(Gogo* gogo, Named_object*,
+                           Statement_inserter* inserter, int)
 {
-  source_location location = this->location();
+  Location location = this->location();
   Operator op = this->op_;
   Expression* left = this->left_;
   Expression* right = this->right_;
@@ -5718,9 +5812,183 @@ Binary_expression::do_lower(Gogo*, Named_object*, Statement_inserter*, int)
       mpz_clear(right_val);
     }
 
+  // Lower struct and array comparisons.
+  if (op == OPERATOR_EQEQ || op == OPERATOR_NOTEQ)
+    {
+      if (left->type()->struct_type() != NULL)
+       return this->lower_struct_comparison(gogo, inserter);
+      else if (left->type()->array_type() != NULL
+              && !left->type()->is_slice_type())
+       return this->lower_array_comparison(gogo, inserter);
+    }
+
   return this;
 }
 
+// Lower a struct comparison.
+
+Expression*
+Binary_expression::lower_struct_comparison(Gogo* gogo,
+                                          Statement_inserter* inserter)
+{
+  Struct_type* st = this->left_->type()->struct_type();
+  Struct_type* st2 = this->right_->type()->struct_type();
+  if (st2 == NULL)
+    return this;
+  if (st != st2 && !Type::are_identical(st, st2, false, NULL))
+    return this;
+  if (!Type::are_compatible_for_comparison(true, this->left_->type(),
+                                          this->right_->type(), NULL))
+    return this;
+
+  // See if we can compare using memcmp.  As a heuristic, we use
+  // memcmp rather than field references and comparisons if there are
+  // more than two fields.
+  if (st->compare_is_identity() && st->total_field_count() > 2)
+    return this->lower_compare_to_memcmp(gogo, inserter);
+
+  Location loc = this->location();
+
+  Expression* left = this->left_;
+  Temporary_statement* left_temp = NULL;
+  if (left->var_expression() == NULL
+      && left->temporary_reference_expression() == NULL)
+    {
+      left_temp = Statement::make_temporary(left->type(), NULL, loc);
+      inserter->insert(left_temp);
+      left = Expression::make_set_and_use_temporary(left_temp, left, loc);
+    }
+
+  Expression* right = this->right_;
+  Temporary_statement* right_temp = NULL;
+  if (right->var_expression() == NULL
+      && right->temporary_reference_expression() == NULL)
+    {
+      right_temp = Statement::make_temporary(right->type(), NULL, loc);
+      inserter->insert(right_temp);
+      right = Expression::make_set_and_use_temporary(right_temp, right, loc);
+    }
+
+  Expression* ret = Expression::make_boolean(true, loc);
+  const Struct_field_list* fields = st->fields();
+  unsigned int field_index = 0;
+  for (Struct_field_list::const_iterator pf = fields->begin();
+       pf != fields->end();
+       ++pf, ++field_index)
+    {
+      if (field_index > 0)
+       {
+         if (left_temp == NULL)
+           left = left->copy();
+         else
+           left = Expression::make_temporary_reference(left_temp, loc);
+         if (right_temp == NULL)
+           right = right->copy();
+         else
+           right = Expression::make_temporary_reference(right_temp, loc);
+       }
+      Expression* f1 = Expression::make_field_reference(left, field_index,
+                                                       loc);
+      Expression* f2 = Expression::make_field_reference(right, field_index,
+                                                       loc);
+      Expression* cond = Expression::make_binary(OPERATOR_EQEQ, f1, f2, loc);
+      ret = Expression::make_binary(OPERATOR_ANDAND, ret, cond, loc);
+    }
+
+  if (this->op_ == OPERATOR_NOTEQ)
+    ret = Expression::make_unary(OPERATOR_NOT, ret, loc);
+
+  return ret;
+}
+
+// Lower an array comparison.
+
+Expression*
+Binary_expression::lower_array_comparison(Gogo* gogo,
+                                         Statement_inserter* inserter)
+{
+  Array_type* at = this->left_->type()->array_type();
+  Array_type* at2 = this->right_->type()->array_type();
+  if (at2 == NULL)
+    return this;
+  if (at != at2 && !Type::are_identical(at, at2, false, NULL))
+    return this;
+  if (!Type::are_compatible_for_comparison(true, this->left_->type(),
+                                          this->right_->type(), NULL))
+    return this;
+
+  // Call memcmp directly if possible.  This may let the middle-end
+  // optimize the call.
+  if (at->compare_is_identity())
+    return this->lower_compare_to_memcmp(gogo, inserter);
+
+  // Call the array comparison function.
+  Named_object* hash_fn;
+  Named_object* equal_fn;
+  at->type_functions(gogo, this->left_->type()->named_type(), NULL, NULL,
+                    &hash_fn, &equal_fn);
+
+  Location loc = this->location();
+
+  Expression* func = Expression::make_func_reference(equal_fn, NULL, loc);
+
+  Expression_list* args = new Expression_list();
+  args->push_back(this->operand_address(inserter, this->left_));
+  args->push_back(this->operand_address(inserter, this->right_));
+  args->push_back(Expression::make_type_info(at, TYPE_INFO_SIZE));
+
+  Expression* ret = Expression::make_call(func, args, false, loc);
+
+  if (this->op_ == OPERATOR_NOTEQ)
+    ret = Expression::make_unary(OPERATOR_NOT, ret, loc);
+
+  return ret;
+}
+
+// Lower a struct or array comparison to a call to memcmp.
+
+Expression*
+Binary_expression::lower_compare_to_memcmp(Gogo*, Statement_inserter* inserter)
+{
+  Location loc = this->location();
+
+  Expression* a1 = this->operand_address(inserter, this->left_);
+  Expression* a2 = this->operand_address(inserter, this->right_);
+  Expression* len = Expression::make_type_info(this->left_->type(),
+                                              TYPE_INFO_SIZE);
+
+  Expression* call = Runtime::make_call(Runtime::MEMCMP, loc, 3, a1, a2, len);
+
+  mpz_t zval;
+  mpz_init_set_ui(zval, 0);
+  Expression* zero = Expression::make_integer(&zval, NULL, loc);
+  mpz_clear(zval);
+
+  return Expression::make_binary(this->op_, call, zero, loc);
+}
+
+// Return the address of EXPR, cast to unsafe.Pointer.
+
+Expression*
+Binary_expression::operand_address(Statement_inserter* inserter,
+                                  Expression* expr)
+{
+  Location loc = this->location();
+
+  if (!expr->is_addressable())
+    {
+      Temporary_statement* temp = Statement::make_temporary(expr->type(), NULL,
+                                                           loc);
+      inserter->insert(temp);
+      expr = Expression::make_set_and_use_temporary(temp, expr, loc);
+    }
+  expr = Expression::make_unary(OPERATOR_AND, expr, loc);
+  static_cast<Unary_expression*>(expr)->set_does_not_escape();
+  Type* void_type = Type::make_void_type();
+  Type* unsafe_pointer_type = Type::make_pointer_type(void_type);
+  return Expression::make_cast(unsafe_pointer_type, expr, loc);
+}
+
 // Return the integer constant value, if it has one.
 
 bool
@@ -6043,12 +6311,12 @@ Binary_expression::do_determine_type(const Type_context* context)
 }
 
 // Report an error if the binary operator OP does not support TYPE.
-// Return whether the operation is OK.  This should not be used for
-// shift.
+// OTYPE is the type of the other operand.  Return whether the
+// operation is OK.  This should not be used for shift.
 
 bool
-Binary_expression::check_operator_type(Operator op, Type* type,
-                                      source_location location)
+Binary_expression::check_operator_type(Operator op, Type* type, Type* otype,
+                                      Location location)
 {
   switch (op)
     {
@@ -6063,39 +6331,28 @@ Binary_expression::check_operator_type(Operator op, Type* type,
 
     case OPERATOR_EQEQ:
     case OPERATOR_NOTEQ:
-      if (type->integer_type() == NULL
-         && type->float_type() == NULL
-         && type->complex_type() == NULL
-         && !type->is_string_type()
-         && type->points_to() == NULL
-         && !type->is_nil_type()
-         && !type->is_boolean_type()
-         && type->interface_type() == NULL
-         && (type->array_type() == NULL
-             || type->array_type()->length() != NULL)
-         && type->map_type() == NULL
-         && type->channel_type() == NULL
-         && type->function_type() == NULL)
-       {
-         error_at(location,
-                  ("expected integer, floating, complex, string, pointer, "
-                   "boolean, interface, slice, map, channel, "
-                   "or function type"));
-         return false;
-       }
+      {
+       std::string reason;
+       if (!Type::are_compatible_for_comparison(true, type, otype, &reason))
+         {
+           error_at(location, "%s", reason.c_str());
+           return false;
+         }
+      }
       break;
 
     case OPERATOR_LT:
     case OPERATOR_LE:
     case OPERATOR_GT:
     case OPERATOR_GE:
-      if (type->integer_type() == NULL
-         && type->float_type() == NULL
-         && !type->is_string_type())
-       {
-         error_at(location, "expected integer, floating, or string type");
-         return false;
-       }
+      {
+       std::string reason;
+       if (!Type::are_compatible_for_comparison(false, type, otype, &reason))
+         {
+           error_at(location, "%s", reason.c_str());
+           return false;
+         }
+      }
       break;
 
     case OPERATOR_PLUS:
@@ -6180,8 +6437,10 @@ Binary_expression::do_check_types(Gogo*)
          return;
        }
       if (!Binary_expression::check_operator_type(this->op_, left_type,
+                                                 right_type,
                                                  this->location())
          || !Binary_expression::check_operator_type(this->op_, right_type,
+                                                    left_type,
                                                     this->location()))
        {
          this->set_is_error();
@@ -6196,6 +6455,7 @@ Binary_expression::do_check_types(Gogo*)
          return;
        }
       if (!Binary_expression::check_operator_type(this->op_, left_type,
+                                                 right_type,
                                                  this->location()))
        {
          this->set_is_error();
@@ -6222,7 +6482,7 @@ Binary_expression::do_check_types(Gogo*)
                {
                  this->report_error(_("negative shift count"));
                  mpz_set_ui(val, 0);
-                 source_location rloc = this->right_->location();
+                 Location rloc = this->right_->location();
                  this->right_ = Expression::make_integer(&val, right_type,
                                                          rloc);
                }
@@ -6354,12 +6614,13 @@ Binary_expression::do_get_tree(Translate_context* context)
          if (eval_saved == NULL_TREE)
            eval_saved = right;
          else
-           eval_saved = fold_build2_loc(this->location(), COMPOUND_EXPR,
+           eval_saved = fold_build2_loc(this->location().gcc_location(),
+                                         COMPOUND_EXPR,
                                         void_type_node, eval_saved, right);
        }
     }
 
-  tree ret = fold_build2_loc(this->location(),
+  tree ret = fold_build2_loc(this->location().gcc_location(),
                             code,
                             compute_type != NULL_TREE ? compute_type : type,
                             left, right);
@@ -6378,35 +6639,38 @@ Binary_expression::do_get_tree(Translate_context* context)
       tree compare = fold_build2(LT_EXPR, boolean_type_node, right,
                                 build_int_cst_type(TREE_TYPE(right), bits));
 
-      tree overflow_result = fold_convert_loc(this->location(),
+      tree overflow_result = fold_convert_loc(this->location().gcc_location(),
                                              TREE_TYPE(left),
                                              integer_zero_node);
       if (this->op_ == OPERATOR_RSHIFT
          && !this->left_->type()->integer_type()->is_unsigned())
        {
-         tree neg = fold_build2_loc(this->location(), LT_EXPR,
-                                    boolean_type_node, left,
-                                    fold_convert_loc(this->location(),
-                                                     TREE_TYPE(left),
-                                                     integer_zero_node));
-         tree neg_one = fold_build2_loc(this->location(),
-                                        MINUS_EXPR, TREE_TYPE(left),
-                                        fold_convert_loc(this->location(),
-                                                         TREE_TYPE(left),
-                                                         integer_zero_node),
-                                        fold_convert_loc(this->location(),
-                                                         TREE_TYPE(left),
-                                                         integer_one_node));
-         overflow_result = fold_build3_loc(this->location(), COND_EXPR,
-                                           TREE_TYPE(left), neg, neg_one,
-                                           overflow_result);
-       }
-
-      ret = fold_build3_loc(this->location(), COND_EXPR, TREE_TYPE(left),
-                           compare, ret, overflow_result);
+         tree neg =
+            fold_build2_loc(this->location().gcc_location(), LT_EXPR,
+                            boolean_type_node, left,
+                            fold_convert_loc(this->location().gcc_location(),
+                                             TREE_TYPE(left),
+                                             integer_zero_node));
+         tree neg_one =
+            fold_build2_loc(this->location().gcc_location(),
+                            MINUS_EXPR, TREE_TYPE(left),
+                            fold_convert_loc(this->location().gcc_location(),
+                                             TREE_TYPE(left),
+                                             integer_zero_node),
+                            fold_convert_loc(this->location().gcc_location(),
+                                             TREE_TYPE(left),
+                                             integer_one_node));
+         overflow_result =
+            fold_build3_loc(this->location().gcc_location(), COND_EXPR,
+                            TREE_TYPE(left), neg, neg_one,
+                            overflow_result);
+       }
+
+      ret = fold_build3_loc(this->location().gcc_location(), COND_EXPR,
+                            TREE_TYPE(left), compare, ret, overflow_result);
 
       if (eval_saved != NULL_TREE)
-       ret = fold_build2_loc(this->location(), COMPOUND_EXPR,
+       ret = fold_build2_loc(this->location().gcc_location(), COMPOUND_EXPR,
                              TREE_TYPE(ret), eval_saved, ret);
     }
 
@@ -6622,7 +6886,7 @@ Binary_expression::do_dump_expression(Ast_dump_context* ast_dump_context) const
 
 Expression*
 Expression::make_binary(Operator op, Expression* left, Expression* right,
-                       source_location location)
+                       Location location)
 {
   return new Binary_expression(op, left, right, location);
 }
@@ -6633,7 +6897,7 @@ tree
 Expression::comparison_tree(Translate_context* context, Operator op,
                            Type* left_type, tree left_tree,
                            Type* right_type, tree right_tree,
-                           source_location location)
+                           Location location)
 {
   enum tree_code code;
   switch (op)
@@ -6702,7 +6966,7 @@ Expression::comparison_tree(Translate_context* context, Operator op,
       else if (TREE_ADDRESSABLE(TREE_TYPE(right_tree)) || DECL_P(right_tree))
        {
          make_tmp = NULL_TREE;
-         arg = build_fold_addr_expr_loc(location, right_tree);
+         arg = build_fold_addr_expr_loc(location.gcc_location(), right_tree);
          if (DECL_P(right_tree))
            TREE_ADDRESSABLE(right_tree) = 1;
        }
@@ -6714,10 +6978,10 @@ Expression::comparison_tree(Translate_context* context, Operator op,
          DECL_INITIAL(tmp) = right_tree;
          TREE_ADDRESSABLE(tmp) = 1;
          make_tmp = build1(DECL_EXPR, void_type_node, tmp);
-         SET_EXPR_LOCATION(make_tmp, location);
-         arg = build_fold_addr_expr_loc(location, tmp);
+         SET_EXPR_LOCATION(make_tmp, location.gcc_location());
+         arg = build_fold_addr_expr_loc(location.gcc_location(), tmp);
        }
-      arg = fold_convert_loc(location, ptr_type_node, arg);
+      arg = fold_convert_loc(location.gcc_location(), ptr_type_node, arg);
 
       tree descriptor = right_type->type_descriptor_pointer(context->gogo(),
                                                            location);
@@ -6872,7 +7136,7 @@ Expression::comparison_tree(Translate_context* context, Operator op,
 
   tree ret = fold_build2(code, boolean_type_node, left_tree, right_tree);
   if (CAN_HAVE_LOCATION_P(ret))
-    SET_EXPR_LOCATION(ret, location);
+    SET_EXPR_LOCATION(ret, location.gcc_location());
   return ret;
 }
 
@@ -6972,7 +7236,7 @@ Bound_method_expression::do_dump_expression(Ast_dump_context* ast_dump_context)
 
 Bound_method_expression*
 Expression::make_bound_method(Expression* expr, Named_object* method,
-                             source_location location)
+                             Location location)
 {
   return new Bound_method_expression(expr, method, location);
 }
@@ -6984,7 +7248,7 @@ class Builtin_call_expression : public Call_expression
 {
  public:
   Builtin_call_expression(Gogo* gogo, Expression* fn, Expression_list* args,
-                         bool is_varargs, source_location location);
+                         bool is_varargs, Location location);
 
  protected:
   // This overrides Call_expression::do_lower.
@@ -7048,6 +7312,7 @@ class Builtin_call_expression : public Call_expression
       BUILTIN_CLOSE,
       BUILTIN_COMPLEX,
       BUILTIN_COPY,
+      BUILTIN_DELETE,
       BUILTIN_IMAG,
       BUILTIN_LEN,
       BUILTIN_MAKE,
@@ -7096,7 +7361,7 @@ Builtin_call_expression::Builtin_call_expression(Gogo* gogo,
                                                 Expression* fn,
                                                 Expression_list* args,
                                                 bool is_varargs,
-                                                source_location location)
+                                                Location location)
   : Call_expression(fn, args, is_varargs, location),
     gogo_(gogo), code_(BUILTIN_INVALID), seen_(false)
 {
@@ -7113,6 +7378,8 @@ Builtin_call_expression::Builtin_call_expression(Gogo* gogo,
     this->code_ = BUILTIN_COMPLEX;
   else if (name == "copy")
     this->code_ = BUILTIN_COPY;
+  else if (name == "delete")
+    this->code_ = BUILTIN_DELETE;
   else if (name == "imag")
     this->code_ = BUILTIN_IMAG;
   else if (name == "len")
@@ -7206,34 +7473,15 @@ Builtin_call_expression::do_lower(Gogo* gogo, Named_object* function,
   if (this->classification() == EXPRESSION_ERROR)
     return this;
 
+  Location loc = this->location();
+
   if (this->is_varargs() && this->code_ != BUILTIN_APPEND)
     {
       this->report_error(_("invalid use of %<...%> with builtin function"));
-      return Expression::make_error(this->location());
+      return Expression::make_error(loc);
     }
 
-  if (this->code_ == BUILTIN_NEW)
-    {
-      const Expression_list* args = this->args();
-      if (args == NULL || args->size() < 1)
-       this->report_error(_("not enough arguments"));
-      else if (args->size() > 1)
-       this->report_error(_("too many arguments"));
-      else
-       {
-         Expression* arg = args->front();
-         if (!arg->is_type_expression())
-           {
-             error_at(arg->location(), "expected type");
-             this->set_is_error();
-           }
-         else
-           return Expression::make_allocation(arg->type(), this->location());
-       }
-    }
-  else if (this->code_ == BUILTIN_MAKE)
-    return this->lower_make();
-  else if (this->is_constant())
+  if (this->is_constant())
     {
       // We can only lower len and cap if there are no function calls
       // in the arguments.  Otherwise we have to make the call.
@@ -7254,8 +7502,7 @@ Builtin_call_expression::do_lower(Gogo* gogo, Named_object* function,
       Type* type;
       if (this->integer_constant_value(true, ival, &type))
        {
-         Expression* ret = Expression::make_integer(&ival, type,
-                                                    this->location());
+         Expression* ret = Expression::make_integer(&ival, type, loc);
          mpz_clear(ival);
          return ret;
        }
@@ -7265,8 +7512,7 @@ Builtin_call_expression::do_lower(Gogo* gogo, Named_object* function,
       mpfr_init(rval);
       if (this->float_constant_value(rval, &type))
        {
-         Expression* ret = Expression::make_float(&rval, type,
-                                                  this->location());
+         Expression* ret = Expression::make_float(&rval, type, loc);
          mpfr_clear(rval);
          return ret;
        }
@@ -7275,8 +7521,7 @@ Builtin_call_expression::do_lower(Gogo* gogo, Named_object* function,
       mpfr_init(imag);
       if (this->complex_constant_value(rval, imag, &type))
        {
-         Expression* ret = Expression::make_complex(&rval, &imag, type,
-                                                    this->location());
+         Expression* ret = Expression::make_complex(&rval, &imag, type, loc);
          mpfr_clear(rval);
          mpfr_clear(imag);
          return ret;
@@ -7284,34 +7529,100 @@ Builtin_call_expression::do_lower(Gogo* gogo, Named_object* function,
       mpfr_clear(rval);
       mpfr_clear(imag);
     }
-  else if (this->code_ == BUILTIN_RECOVER)
+
+  switch (this->code_)
     {
+    default:
+      break;
+
+    case BUILTIN_NEW:
+      {
+       const Expression_list* args = this->args();
+       if (args == NULL || args->size() < 1)
+         this->report_error(_("not enough arguments"));
+       else if (args->size() > 1)
+         this->report_error(_("too many arguments"));
+       else
+         {
+           Expression* arg = args->front();
+           if (!arg->is_type_expression())
+             {
+               error_at(arg->location(), "expected type");
+               this->set_is_error();
+             }
+           else
+             return Expression::make_allocation(arg->type(), loc);
+         }
+      }
+      break;
+
+    case BUILTIN_MAKE:
+      return this->lower_make();
+
+    case BUILTIN_RECOVER:
       if (function != NULL)
        function->func_value()->set_calls_recover();
       else
        {
          // Calling recover outside of a function always returns the
          // nil empty interface.
-         Type* eface = Type::make_interface_type(NULL, this->location());
-         return Expression::make_cast(eface,
-                                      Expression::make_nil(this->location()),
-                                      this->location());
+         Type* eface = Type::make_interface_type(NULL, loc);
+         return Expression::make_cast(eface, Expression::make_nil(loc), loc);
        }
-    }
-  else if (this->code_ == BUILTIN_APPEND)
-    {
-      // Lower the varargs.
-      const Expression_list* args = this->args();
-      if (args == NULL || args->empty())
-       return this;
-      Type* slice_type = args->front()->type();
-      if (!slice_type->is_slice_type())
-       {
-         error_at(args->front()->location(), "argument 1 must be a slice");
-         this->set_is_error();
+      break;
+
+    case BUILTIN_APPEND:
+      {
+       // Lower the varargs.
+       const Expression_list* args = this->args();
+       if (args == NULL || args->empty())
          return this;
-       }
-      this->lower_varargs(gogo, function, inserter, slice_type, 2);
+       Type* slice_type = args->front()->type();
+       if (!slice_type->is_slice_type())
+         {
+           error_at(args->front()->location(), "argument 1 must be a slice");
+           this->set_is_error();
+           return this;
+         }
+       this->lower_varargs(gogo, function, inserter, slice_type, 2);
+      }
+      break;
+
+    case BUILTIN_DELETE:
+      {
+       // Lower to a runtime function call.
+       const Expression_list* args = this->args();
+       if (args == NULL || args->size() < 2)
+         this->report_error(_("not enough arguments"));
+       else if (args->size() > 2)
+         this->report_error(_("too many arguments"));
+       else if (args->front()->type()->map_type() == NULL)
+         this->report_error(_("argument 1 must be a map"));
+       else
+         {
+           // Since this function returns no value it must appear in
+           // a statement by itself, so we don't have to worry about
+           // order of evaluation of values around it.  Evaluate the
+           // map first to get order of evaluation right.
+           Map_type* mt = args->front()->type()->map_type();
+           Temporary_statement* map_temp =
+             Statement::make_temporary(mt, args->front(), loc);
+           inserter->insert(map_temp);
+
+           Temporary_statement* key_temp =
+             Statement::make_temporary(mt->key_type(), args->back(), loc);
+           inserter->insert(key_temp);
+
+           Expression* e1 = Expression::make_temporary_reference(map_temp,
+                                                                 loc);
+           Expression* e2 = Expression::make_temporary_reference(key_temp,
+                                                                 loc);
+           e2 = Expression::make_unary(OPERATOR_AND, e2, loc);
+           return Runtime::make_call(Runtime::MAPDELETE, this->location(),
+                                     2, e1, e2);
+         }
+      }
+      break;
     }
 
   return this;
@@ -7322,7 +7633,7 @@ Builtin_call_expression::do_lower(Gogo* gogo, Named_object* function,
 Expression*
 Builtin_call_expression::lower_make()
 {
-  source_location loc = this->location();
+  Location loc = this->location();
 
   const Expression_list* args = this->args();
   if (args == NULL || args->size() < 1)
@@ -7401,7 +7712,7 @@ Builtin_call_expression::lower_make()
       return Expression::make_error(this->location());
     }
 
-  source_location type_loc = first_arg->location();
+  Location type_loc = first_arg->location();
   Expression* type_arg;
   if (is_slice || is_chan)
     type_arg = Expression::make_type_descriptor(type, type_loc);
@@ -7668,35 +7979,32 @@ Builtin_call_expression::do_integer_constant_value(bool iota_is_constant,
        return false;
       if (arg_type->named_type() != NULL)
        arg_type->named_type()->convert(this->gogo_);
-      tree arg_type_tree = type_to_tree(arg_type->get_backend(this->gogo_));
-      if (arg_type_tree == error_mark_node)
-       return false;
-      unsigned long val_long;
+
+      unsigned int ret;
       if (this->code_ == BUILTIN_SIZEOF)
        {
-         tree type_size = TYPE_SIZE_UNIT(arg_type_tree);
-         go_assert(TREE_CODE(type_size) == INTEGER_CST);
-         if (TREE_INT_CST_HIGH(type_size) != 0)
-           return false;
-         unsigned HOST_WIDE_INT val_wide = TREE_INT_CST_LOW(type_size);
-         val_long = static_cast<unsigned long>(val_wide);
-         if (val_long != val_wide)
+         if (!arg_type->backend_type_size(this->gogo_, &ret))
            return false;
        }
       else if (this->code_ == BUILTIN_ALIGNOF)
        {
          if (arg->field_reference_expression() == NULL)
-           val_long = go_type_alignment(arg_type_tree);
+           {
+             if (!arg_type->backend_type_align(this->gogo_, &ret))
+               return false;
+           }
          else
            {
              // Calling unsafe.Alignof(s.f) returns the alignment of
              // the type of f when it is used as a field in a struct.
-             val_long = go_field_alignment(arg_type_tree);
+             if (!arg_type->backend_type_field_align(this->gogo_, &ret))
+               return false;
            }
        }
       else
        go_unreachable();
-      mpz_set_ui(val, val_long);
+
+      mpz_set_ui(val, ret);
       *ptype = NULL;
       return true;
     }
@@ -7714,21 +8022,12 @@ Builtin_call_expression::do_integer_constant_value(bool iota_is_constant,
        return false;
       if (st->named_type() != NULL)
        st->named_type()->convert(this->gogo_);
-      tree struct_tree = type_to_tree(st->get_backend(this->gogo_));
-      go_assert(TREE_CODE(struct_tree) == RECORD_TYPE);
-      tree field = TYPE_FIELDS(struct_tree);
-      for (unsigned int index = farg->field_index(); index > 0; --index)
-       {
-         field = DECL_CHAIN(field);
-         go_assert(field != NULL_TREE);
-       }
-      HOST_WIDE_INT offset_wide = int_byte_position (field);
-      if (offset_wide < 0)
+      unsigned int offset;
+      if (!st->struct_type()->backend_field_offset(this->gogo_,
+                                                  farg->field_index(),
+                                                  &offset))
        return false;
-      unsigned long offset_long = static_cast<unsigned long>(offset_wide);
-      if (offset_long != static_cast<unsigned HOST_WIDE_INT>(offset_wide))
-       return false;
-      mpz_set_ui(val, offset_long);
+      mpz_set_ui(val, offset);
       return true;
     }
   return false;
@@ -7845,6 +8144,7 @@ Builtin_call_expression::do_discarding_value()
 
     case BUILTIN_CLOSE:
     case BUILTIN_COPY:
+    case BUILTIN_DELETE:
     case BUILTIN_PANIC:
     case BUILTIN_PRINT:
     case BUILTIN_PRINTLN:
@@ -7882,13 +8182,14 @@ Builtin_call_expression::do_type()
       return Type::lookup_integer_type("int");
 
     case BUILTIN_CLOSE:
+    case BUILTIN_DELETE:
     case BUILTIN_PANIC:
     case BUILTIN_PRINT:
     case BUILTIN_PRINTLN:
       return Type::make_void_type();
 
     case BUILTIN_RECOVER:
-      return Type::make_interface_type(NULL, BUILTINS_LOCATION);
+      return Type::make_interface_type(NULL, Linemap::predeclared_location());
 
     case BUILTIN_APPEND:
       {
@@ -8153,6 +8454,8 @@ Builtin_call_expression::do_check_types(Gogo*)
        {
          if (this->one_arg()->type()->channel_type() == NULL)
            this->report_error(_("argument must be channel"));
+         else if (!this->one_arg()->type()->channel_type()->may_send())
+           this->report_error(_("cannot close receive-only channel"));
        }
       break;
 
@@ -8301,7 +8604,7 @@ tree
 Builtin_call_expression::do_get_tree(Translate_context* context)
 {
   Gogo* gogo = context->gogo();
-  source_location location = this->location();
+  Location location = this->location();
   switch (this->code_)
     {
     case BUILTIN_INVALID:
@@ -8472,7 +8775,8 @@ Builtin_call_expression::do_get_tree(Translate_context* context)
                    fnname = "__go_print_uint64";
                    Type* itype = Type::lookup_integer_type("uint64");
                    Btype* bitype = itype->get_backend(gogo);
-                   arg = fold_convert_loc(location, type_to_tree(bitype), arg);
+                   arg = fold_convert_loc(location.gcc_location(),
+                                           type_to_tree(bitype), arg);
                  }
                else if (type->integer_type() != NULL)
                  {
@@ -8481,22 +8785,24 @@ Builtin_call_expression::do_get_tree(Translate_context* context)
                    fnname = "__go_print_int64";
                    Type* itype = Type::lookup_integer_type("int64");
                    Btype* bitype = itype->get_backend(gogo);
-                   arg = fold_convert_loc(location, type_to_tree(bitype), arg);
+                   arg = fold_convert_loc(location.gcc_location(),
+                                           type_to_tree(bitype), arg);
                  }
                else if (type->float_type() != NULL)
                  {
                    static tree print_double_fndecl;
                    pfndecl = &print_double_fndecl;
                    fnname = "__go_print_double";
-                   arg = fold_convert_loc(location, double_type_node, arg);
+                   arg = fold_convert_loc(location.gcc_location(),
+                                           double_type_node, arg);
                  }
                else if (type->complex_type() != NULL)
                  {
                    static tree print_complex_fndecl;
                    pfndecl = &print_complex_fndecl;
                    fnname = "__go_print_complex";
-                   arg = fold_convert_loc(location, complex_double_type_node,
-                                          arg);
+                   arg = fold_convert_loc(location.gcc_location(),
+                                           complex_double_type_node, arg);
                  }
                else if (type->is_boolean_type())
                  {
@@ -8512,7 +8818,8 @@ Builtin_call_expression::do_get_tree(Translate_context* context)
                    static tree print_pointer_fndecl;
                    pfndecl = &print_pointer_fndecl;
                    fnname = "__go_print_pointer";
-                   arg = fold_convert_loc(location, ptr_type_node, arg);
+                   arg = fold_convert_loc(location.gcc_location(),
+                                           ptr_type_node, arg);
                  }
                else if (type->interface_type() != NULL)
                  {
@@ -8575,7 +8882,8 @@ Builtin_call_expression::do_get_tree(Translate_context* context)
        tree arg_tree = arg->get_tree(context);
        if (arg_tree == error_mark_node)
          return error_mark_node;
-       Type *empty = Type::make_interface_type(NULL, BUILTINS_LOCATION);
+       Type *empty =
+         Type::make_interface_type(NULL, Linemap::predeclared_location());
        arg_tree = Expression::convert_for_assignment(context, empty,
                                                      arg->type(),
                                                      arg_tree, location);
@@ -8607,7 +8915,8 @@ Builtin_call_expression::do_get_tree(Translate_context* context)
        if (arg_tree == error_mark_node)
          return error_mark_node;
 
-       Type *empty = Type::make_interface_type(NULL, BUILTINS_LOCATION);
+       Type *empty =
+         Type::make_interface_type(NULL, Linemap::predeclared_location());
        tree empty_tree = type_to_tree(empty->get_backend(context->gogo()));
 
        Type* nil_type = Type::make_nil_type();
@@ -8643,8 +8952,8 @@ Builtin_call_expression::do_get_tree(Translate_context* context)
          }
        if (call == error_mark_node)
          return error_mark_node;
-       return fold_build3_loc(location, COND_EXPR, empty_tree, arg_tree,
-                              call, empty_nil_tree);
+       return fold_build3_loc(location.gcc_location(), COND_EXPR, empty_tree,
+                               arg_tree, call, empty_nil_tree);
       }
 
     case BUILTIN_CLOSE:
@@ -8726,9 +9035,10 @@ Builtin_call_expression::do_get_tree(Translate_context* context)
 
        arg1_len = save_expr(arg1_len);
        arg2_len = save_expr(arg2_len);
-       tree len = fold_build3_loc(location, COND_EXPR, TREE_TYPE(arg1_len),
-                                  fold_build2_loc(location, LT_EXPR,
-                                                  boolean_type_node,
+       tree len = fold_build3_loc(location.gcc_location(), COND_EXPR,
+                                   TREE_TYPE(arg1_len),
+                                  fold_build2_loc(location.gcc_location(),
+                                                   LT_EXPR, boolean_type_node,
                                                   arg1_len, arg2_len),
                                   arg1_len, arg2_len);
        len = save_expr(len);
@@ -8739,15 +9049,18 @@ Builtin_call_expression::do_get_tree(Translate_context* context)
        if (element_type_tree == error_mark_node)
          return error_mark_node;
        tree element_size = TYPE_SIZE_UNIT(element_type_tree);
-       tree bytecount = fold_convert_loc(location, TREE_TYPE(element_size),
-                                         len);
-       bytecount = fold_build2_loc(location, MULT_EXPR,
+       tree bytecount = fold_convert_loc(location.gcc_location(),
+                                          TREE_TYPE(element_size), len);
+       bytecount = fold_build2_loc(location.gcc_location(), MULT_EXPR,
                                    TREE_TYPE(element_size),
                                    bytecount, element_size);
-       bytecount = fold_convert_loc(location, size_type_node, bytecount);
+       bytecount = fold_convert_loc(location.gcc_location(), size_type_node,
+                                     bytecount);
 
-       arg1_val = fold_convert_loc(location, ptr_type_node, arg1_val);
-       arg2_val = fold_convert_loc(location, ptr_type_node, arg2_val);
+       arg1_val = fold_convert_loc(location.gcc_location(), ptr_type_node,
+                                    arg1_val);
+       arg2_val = fold_convert_loc(location.gcc_location(), ptr_type_node,
+                                    arg2_val);
 
        static tree copy_fndecl;
        tree call = Gogo::call_builtin(&copy_fndecl,
@@ -8764,8 +9077,8 @@ Builtin_call_expression::do_get_tree(Translate_context* context)
        if (call == error_mark_node)
          return error_mark_node;
 
-       return fold_build2_loc(location, COMPOUND_EXPR, TREE_TYPE(len),
-                              call, len);
+       return fold_build2_loc(location.gcc_location(), COMPOUND_EXPR,
+                               TREE_TYPE(len), call, len);
       }
 
     case BUILTIN_APPEND:
@@ -8815,9 +9128,11 @@ Builtin_call_expression::do_get_tree(Translate_context* context)
             element_size = TYPE_SIZE_UNIT(element_type_tree);
          }
 
-       arg2_val = fold_convert_loc(location, ptr_type_node, arg2_val);
-       arg2_len = fold_convert_loc(location, size_type_node, arg2_len);
-       element_size = fold_convert_loc(location, size_type_node,
+       arg2_val = fold_convert_loc(location.gcc_location(), ptr_type_node,
+                                    arg2_val);
+       arg2_len = fold_convert_loc(location.gcc_location(), size_type_node,
+                                    arg2_len);
+       element_size = fold_convert_loc(location.gcc_location(), size_type_node,
                                        element_size);
 
        if (arg2_val == error_mark_node
@@ -8854,11 +9169,11 @@ Builtin_call_expression::do_get_tree(Translate_context* context)
          return error_mark_node;
        go_assert(COMPLEX_FLOAT_TYPE_P(TREE_TYPE(arg_tree)));
        if (this->code_ == BUILTIN_REAL)
-         return fold_build1_loc(location, REALPART_EXPR,
+         return fold_build1_loc(location.gcc_location(), REALPART_EXPR,
                                 TREE_TYPE(TREE_TYPE(arg_tree)),
                                 arg_tree);
        else
-         return fold_build1_loc(location, IMAGPART_EXPR,
+         return fold_build1_loc(location.gcc_location(), IMAGPART_EXPR,
                                 TREE_TYPE(TREE_TYPE(arg_tree)),
                                 arg_tree);
       }
@@ -8874,7 +9189,7 @@ Builtin_call_expression::do_get_tree(Translate_context* context)
        go_assert(TYPE_MAIN_VARIANT(TREE_TYPE(r))
                   == TYPE_MAIN_VARIANT(TREE_TYPE(i)));
        go_assert(SCALAR_FLOAT_TYPE_P(TREE_TYPE(r)));
-       return fold_build2_loc(location, COMPLEX_EXPR,
+       return fold_build2_loc(location.gcc_location(), COMPLEX_EXPR,
                               build_complex_type(TREE_TYPE(r)),
                               r, i);
       }
@@ -8962,7 +9277,7 @@ Expression*
 Call_expression::do_lower(Gogo* gogo, Named_object* function,
                          Statement_inserter* inserter, int)
 {
-  source_location loc = this->location();
+  Location loc = this->location();
 
   // A type cast can look like a function call.
   if (this->fn_->is_type_expression()
@@ -9109,7 +9424,7 @@ Call_expression::lower_varargs(Gogo* gogo, Named_object* function,
   if (this->varargs_are_lowered_)
     return;
 
-  source_location loc = this->location();
+  Location loc = this->location();
 
   go_assert(param_count > 0);
   go_assert(varargs_type->is_slice_type());
@@ -9160,7 +9475,7 @@ Call_expression::lower_varargs(Gogo* gogo, Named_object* function,
            {
              // Check types here so that we get a better message.
              Type* patype = (*pa)->type();
-             source_location paloc = (*pa)->location();
+             Location paloc = (*pa)->location();
              if (!this->check_argument_type(i, element_type, patype,
                                             paloc, issued_error))
                continue;
@@ -9359,7 +9674,7 @@ Call_expression::determining_types()
 bool
 Call_expression::check_argument_type(int i, const Type* parameter_type,
                                     const Type* argument_type,
-                                    source_location argument_location,
+                                    Location argument_location,
                                     bool issued_error)
 {
   std::string reason;
@@ -9508,7 +9823,7 @@ Call_expression::do_get_tree(Translate_context* context)
     return error_mark_node;
 
   Gogo* gogo = context->gogo();
-  source_location location = this->location();
+  Location location = this->location();
 
   Func_expression* func = this->fn_->func_expression();
   Interface_field_reference_expression* interface_method =
@@ -9601,7 +9916,7 @@ Call_expression::do_get_tree(Translate_context* context)
       tree fnt = type_to_tree(fntype->get_backend(gogo));
       if (fnt == error_mark_node)
        return error_mark_node;
-      fn = fold_convert_loc(location, fnt, fn);
+      fn = fold_convert_loc(location.gcc_location(), fnt, fn);
     }
 
   // This is to support builtin math functions when using 80387 math.
@@ -9624,7 +9939,8 @@ Call_expression::do_get_tree(Translate_context* context)
            excess_type = NULL_TREE;
          else
            {
-             fn = build_fold_addr_expr_loc(location, excess_fndecl);
+             fn = build_fold_addr_expr_loc(location.gcc_location(),
+                                            excess_fndecl);
              for (int i = 0; i < nargs; ++i)
                args[i] = ::convert(excess_type, args[i]);
            }
@@ -9635,7 +9951,7 @@ Call_expression::do_get_tree(Translate_context* context)
                              fn, nargs, args);
   delete[] args;
 
-  SET_EXPR_LOCATION(ret, location);
+  SET_EXPR_LOCATION(ret, location.gcc_location());
 
   if (has_closure)
     {
@@ -9651,7 +9967,7 @@ Call_expression::do_get_tree(Translate_context* context)
   if (TREE_TYPE(ret) == ptr_type_node)
     {
       tree t = type_to_tree(this->type()->base()->get_backend(gogo));
-      ret = fold_convert_loc(location, t, ret);
+      ret = fold_convert_loc(location.gcc_location(), t, ret);
     }
 
   if (excess_type != NULL_TREE)
@@ -9684,7 +10000,7 @@ Call_expression::set_results(Translate_context* context, tree call_tree)
       return call_tree;
     }
 
-  source_location loc = this->location();
+  Location loc = this->location();
   tree field = TYPE_FIELDS(TREE_TYPE(call_tree));
   size_t rc = this->result_count();
   for (size_t i = 0; i < rc; ++i, field = DECL_CHAIN(field))
@@ -9699,10 +10015,10 @@ Call_expression::set_results(Translate_context* context, tree call_tree)
       if (temp_tree == error_mark_node)
        continue;
 
-      tree val_tree = build3_loc(loc, COMPONENT_REF, TREE_TYPE(field),
-                                call_tree, field, NULL_TREE);
-      tree set_tree = build2_loc(loc, MODIFY_EXPR, void_type_node, temp_tree,
-                                val_tree);
+      tree val_tree = build3_loc(loc.gcc_location(), COMPONENT_REF,
+                                 TREE_TYPE(field), call_tree, field, NULL_TREE);
+      tree set_tree = build2_loc(loc.gcc_location(), MODIFY_EXPR,
+                                 void_type_node, temp_tree, val_tree);
 
       append_to_statement_list(set_tree, &stmt_list);
     }
@@ -9728,7 +10044,7 @@ Call_expression::do_dump_expression(Ast_dump_context* ast_dump_context) const
 
 Call_expression*
 Expression::make_call(Expression* fn, Expression_list* args, bool is_varargs,
-                     source_location location)
+                     Location location)
 {
   return new Call_expression(fn, args, is_varargs, location);
 }
@@ -9920,7 +10236,7 @@ Index_expression::do_traverse(Traverse* traverse)
 Expression*
 Index_expression::do_lower(Gogo*, Named_object*, Statement_inserter*, int)
 {
-  source_location location = this->location();
+  Location location = this->location();
   Expression* left = this->left_;
   Expression* start = this->start_;
   Expression* end = this->end_;
@@ -10000,7 +10316,7 @@ Index_expression::do_dump_expression(Ast_dump_context* ast_dump_context)
 
 Expression*
 Expression::make_index(Expression* left, Expression* start, Expression* end,
-                      source_location location)
+                      Location location)
 {
   return new Index_expression(left, start, end, location);
 }
@@ -10011,7 +10327,7 @@ class Array_index_expression : public Expression
 {
  public:
   Array_index_expression(Expression* array, Expression* start,
-                        Expression* end, source_location location)
+                        Expression* end, Location location)
     : Expression(EXPRESSION_ARRAY_INDEX, location),
       array_(array), start_(start), end_(end), type_(NULL)
   { }
@@ -10224,7 +10540,7 @@ tree
 Array_index_expression::do_get_tree(Translate_context* context)
 {
   Gogo* gogo = context->gogo();
-  source_location loc = this->location();
+  Location loc = this->location();
 
   Array_type* array_type = this->array_->type()->array_type();
   if (array_type == NULL)
@@ -10262,9 +10578,10 @@ Array_index_expression::do_get_tree(Translate_context* context)
   bad_index = Expression::check_bounds(start_tree, length_type, bad_index,
                                       loc);
 
-  start_tree = fold_convert_loc(loc, length_type, start_tree);
-  bad_index = fold_build2_loc(loc, TRUTH_OR_EXPR, boolean_type_node, bad_index,
-                             fold_build2_loc(loc,
+  start_tree = fold_convert_loc(loc.gcc_location(), length_type, start_tree);
+  bad_index = fold_build2_loc(loc.gcc_location(), TRUTH_OR_EXPR,
+                              boolean_type_node, bad_index,
+                             fold_build2_loc(loc.gcc_location(),
                                              (this->end_ == NULL
                                               ? GE_EXPR
                                               : GT_EXPR),
@@ -10288,7 +10605,7 @@ Array_index_expression::do_get_tree(Translate_context* context)
                          build3(COND_EXPR, void_type_node,
                                 bad_index, crash, NULL_TREE),
                          start_tree);
-      start_tree = fold_convert_loc(loc, sizetype, start_tree);
+      start_tree = fold_convert_loc(loc.gcc_location(), sizetype, start_tree);
 
       if (array_type->length() != NULL)
        {
@@ -10306,9 +10623,9 @@ Array_index_expression::do_get_tree(Translate_context* context)
          if (element_type_tree == error_mark_node)
            return error_mark_node;
          tree element_size = TYPE_SIZE_UNIT(element_type_tree);
-         tree offset = fold_build2_loc(loc, MULT_EXPR, sizetype,
+         tree offset = fold_build2_loc(loc.gcc_location(), MULT_EXPR, sizetype,
                                        start_tree, element_size);
-         tree ptr = fold_build2_loc(loc, POINTER_PLUS_EXPR,
+         tree ptr = fold_build2_loc(loc.gcc_location(), POINTER_PLUS_EXPR,
                                     TREE_TYPE(values), values, offset);
          return build_fold_indirect_ref(ptr);
        }
@@ -10319,7 +10636,8 @@ Array_index_expression::do_get_tree(Translate_context* context)
   tree capacity_tree = array_type->capacity_tree(gogo, array_tree);
   if (capacity_tree == error_mark_node)
     return error_mark_node;
-  capacity_tree = fold_convert_loc(loc, length_type, capacity_tree);
+  capacity_tree = fold_convert_loc(loc.gcc_location(), length_type,
+                                   capacity_tree);
 
   tree end_tree;
   if (this->end_->is_nil_expression())
@@ -10337,18 +10655,19 @@ Array_index_expression::do_get_tree(Translate_context* context)
       bad_index = Expression::check_bounds(end_tree, length_type, bad_index,
                                           loc);
 
-      end_tree = fold_convert_loc(loc, length_type, end_tree);
+      end_tree = fold_convert_loc(loc.gcc_location(), length_type, end_tree);
 
       capacity_tree = save_expr(capacity_tree);
-      tree bad_end = fold_build2_loc(loc, TRUTH_OR_EXPR, boolean_type_node,
-                                    fold_build2_loc(loc, LT_EXPR,
-                                                    boolean_type_node,
+      tree bad_end = fold_build2_loc(loc.gcc_location(), TRUTH_OR_EXPR,
+                                     boolean_type_node,
+                                    fold_build2_loc(loc.gcc_location(),
+                                                     LT_EXPR, boolean_type_node,
                                                     end_tree, start_tree),
-                                    fold_build2_loc(loc, GT_EXPR,
-                                                    boolean_type_node,
+                                    fold_build2_loc(loc.gcc_location(),
+                                                     GT_EXPR, boolean_type_node,
                                                     end_tree, capacity_tree));
-      bad_index = fold_build2_loc(loc, TRUTH_OR_EXPR, boolean_type_node,
-                                 bad_index, bad_end);
+      bad_index = fold_build2_loc(loc.gcc_location(), TRUTH_OR_EXPR,
+                                  boolean_type_node, bad_index, bad_end);
     }
 
   Type* element_type = array_type->element_type();
@@ -10357,23 +10676,25 @@ Array_index_expression::do_get_tree(Translate_context* context)
     return error_mark_node;
   tree element_size = TYPE_SIZE_UNIT(element_type_tree);
 
-  tree offset = fold_build2_loc(loc, MULT_EXPR, sizetype,
-                               fold_convert_loc(loc, sizetype, start_tree),
+  tree offset = fold_build2_loc(loc.gcc_location(), MULT_EXPR, sizetype,
+                               fold_convert_loc(loc.gcc_location(), sizetype,
+                                                 start_tree),
                                element_size);
 
   tree value_pointer = array_type->value_pointer_tree(gogo, array_tree);
   if (value_pointer == error_mark_node)
     return error_mark_node;
 
-  value_pointer = fold_build2_loc(loc, POINTER_PLUS_EXPR,
+  value_pointer = fold_build2_loc(loc.gcc_location(), POINTER_PLUS_EXPR,
                                  TREE_TYPE(value_pointer),
                                  value_pointer, offset);
 
-  tree result_length_tree = fold_build2_loc(loc, MINUS_EXPR, length_type,
-                                           end_tree, start_tree);
+  tree result_length_tree = fold_build2_loc(loc.gcc_location(), MINUS_EXPR,
+                                            length_type, end_tree, start_tree);
 
-  tree result_capacity_tree = fold_build2_loc(loc, MINUS_EXPR, length_type,
-                                             capacity_tree, start_tree);
+  tree result_capacity_tree = fold_build2_loc(loc.gcc_location(), MINUS_EXPR,
+                                              length_type, capacity_tree,
+                                              start_tree);
 
   tree struct_tree = type_to_tree(this->type()->get_backend(gogo));
   go_assert(TREE_CODE(struct_tree) == RECORD_TYPE);
@@ -10390,13 +10711,15 @@ Array_index_expression::do_get_tree(Translate_context* context)
   field = DECL_CHAIN(field);
   go_assert(strcmp(IDENTIFIER_POINTER(DECL_NAME(field)), "__count") == 0);
   elt->index = field;
-  elt->value = fold_convert_loc(loc, TREE_TYPE(field), result_length_tree);
+  elt->value = fold_convert_loc(loc.gcc_location(), TREE_TYPE(field),
+                                result_length_tree);
 
   elt = VEC_quick_push(constructor_elt, init, NULL);
   field = DECL_CHAIN(field);
   go_assert(strcmp(IDENTIFIER_POINTER(DECL_NAME(field)), "__capacity") == 0);
   elt->index = field;
-  elt->value = fold_convert_loc(loc, TREE_TYPE(field), result_capacity_tree);
+  elt->value = fold_convert_loc(loc.gcc_location(), TREE_TYPE(field),
+                                result_capacity_tree);
 
   tree constructor = build_constructor(struct_tree, init);
 
@@ -10405,7 +10728,8 @@ Array_index_expression::do_get_tree(Translate_context* context)
       && TREE_CONSTANT(result_capacity_tree))
     TREE_CONSTANT(constructor) = 1;
 
-  return fold_build2_loc(loc, COMPOUND_EXPR, TREE_TYPE(constructor),
+  return fold_build2_loc(loc.gcc_location(), COMPOUND_EXPR,
+                         TREE_TYPE(constructor),
                         build3(COND_EXPR, void_type_node,
                                bad_index, crash, NULL_TREE),
                         constructor);
@@ -10425,7 +10749,7 @@ Array_index_expression::do_dump_expression(Ast_dump_context* ast_dump_context)
 
 Expression*
 Expression::make_array_index(Expression* array, Expression* start,
-                            Expression* end, source_location location)
+                            Expression* end, Location location)
 {
   // Taking a slice of a composite literal requires moving the literal
   // onto the heap.
@@ -10443,7 +10767,7 @@ class String_index_expression : public Expression
 {
  public:
   String_index_expression(Expression* string, Expression* start,
-                         Expression* end, source_location location)
+                         Expression* end, Location location)
     : Expression(EXPRESSION_STRING_INDEX, location),
       string_(string), start_(start), end_(end)
   { }
@@ -10581,7 +10905,7 @@ String_index_expression::do_check_types(Gogo*)
 tree
 String_index_expression::do_get_tree(Translate_context* context)
 {
-  source_location loc = this->location();
+  Location loc = this->location();
 
   tree string_tree = this->string_->get_tree(context);
   if (string_tree == error_mark_node)
@@ -10610,7 +10934,7 @@ String_index_expression::do_get_tree(Translate_context* context)
   bad_index = Expression::check_bounds(start_tree, length_type, bad_index,
                                       loc);
 
-  start_tree = fold_convert_loc(loc, length_type, start_tree);
+  start_tree = fold_convert_loc(loc.gcc_location(), length_type, start_tree);
 
   int code = (this->end_ == NULL
              ? RUNTIME_ERROR_STRING_INDEX_OUT_OF_BOUNDS
@@ -10619,17 +10943,19 @@ String_index_expression::do_get_tree(Translate_context* context)
 
   if (this->end_ == NULL)
     {
-      bad_index = fold_build2_loc(loc, TRUTH_OR_EXPR, boolean_type_node,
-                                 bad_index,
-                                 fold_build2_loc(loc, GE_EXPR,
+      bad_index = fold_build2_loc(loc.gcc_location(), TRUTH_OR_EXPR,
+                                  boolean_type_node, bad_index,
+                                 fold_build2_loc(loc.gcc_location(), GE_EXPR,
                                                  boolean_type_node,
                                                  start_tree, length_tree));
 
       tree bytes_tree = String_type::bytes_tree(context->gogo(), string_tree);
-      tree ptr = fold_build2_loc(loc, POINTER_PLUS_EXPR, TREE_TYPE(bytes_tree),
+      tree ptr = fold_build2_loc(loc.gcc_location(), POINTER_PLUS_EXPR,
+                                 TREE_TYPE(bytes_tree),
                                 bytes_tree,
-                                fold_convert_loc(loc, sizetype, start_tree));
-      tree index = build_fold_indirect_ref_loc(loc, ptr);
+                                fold_convert_loc(loc.gcc_location(), sizetype,
+                                                  start_tree));
+      tree index = build_fold_indirect_ref_loc(loc.gcc_location(), ptr);
 
       return build2(COMPOUND_EXPR, TREE_TYPE(index),
                    build3(COND_EXPR, void_type_node,
@@ -10654,7 +10980,8 @@ String_index_expression::do_get_tree(Translate_context* context)
          bad_index = Expression::check_bounds(end_tree, length_type,
                                               bad_index, loc);
 
-         end_tree = fold_convert_loc(loc, length_type, end_tree);
+         end_tree = fold_convert_loc(loc.gcc_location(), length_type,
+                                      end_tree);
        }
 
       static tree strslice_fndecl;
@@ -10699,7 +11026,7 @@ String_index_expression::do_dump_expression(Ast_dump_context* ast_dump_context)
 
 Expression*
 Expression::make_string_index(Expression* string, Expression* start,
-                             Expression* end, source_location location)
+                             Expression* end, Location location)
 {
   return new String_index_expression(string, start, end, location);
 }
@@ -10855,14 +11182,16 @@ Map_index_expression::get_value_pointer(Translate_context* context,
     }
   else
     {
-      tmp = build_decl(this->location(), VAR_DECL, create_tmp_var_name("M"),
+      tmp = build_decl(this->location().gcc_location(), VAR_DECL,
+                       create_tmp_var_name("M"),
                       TREE_TYPE(index_tree));
       DECL_EXTERNAL(tmp) = 0;
       TREE_PUBLIC(tmp) = 0;
       TREE_STATIC(tmp) = 1;
       DECL_ARTIFICIAL(tmp) = 1;
       if (!TREE_CONSTANT(index_tree))
-       make_tmp = fold_build2_loc(this->location(), INIT_EXPR, void_type_node,
+       make_tmp = fold_build2_loc(this->location().gcc_location(),
+                                   INIT_EXPR, void_type_node,
                                   tmp, index_tree);
       else
        {
@@ -10873,9 +11202,10 @@ Map_index_expression::get_value_pointer(Translate_context* context,
        }
       rest_of_decl_compilation(tmp, 1, 0);
     }
-  tree tmpref = fold_convert_loc(this->location(), const_ptr_type_node,
-                                build_fold_addr_expr_loc(this->location(),
-                                                         tmp));
+  tree tmpref =
+    fold_convert_loc(this->location().gcc_location(), const_ptr_type_node,
+                     build_fold_addr_expr_loc(this->location().gcc_location(),
+                                              tmp));
 
   static tree map_index_fndecl;
   tree call = Gogo::call_builtin(&map_index_fndecl,
@@ -10903,7 +11233,8 @@ Map_index_expression::get_value_pointer(Translate_context* context,
     return error_mark_node;
   tree ptr_val_type_tree = build_pointer_type(val_type_tree);
 
-  tree ret = fold_convert_loc(this->location(), ptr_val_type_tree, call);
+  tree ret = fold_convert_loc(this->location().gcc_location(),
+                              ptr_val_type_tree, call);
   if (make_tmp != NULL_TREE)
     ret = build2(COMPOUND_EXPR, ptr_val_type_tree, make_tmp, ret);
   return ret;
@@ -10923,7 +11254,7 @@ Map_index_expression::do_dump_expression(Ast_dump_context* ast_dump_context)
 
 Map_index_expression*
 Expression::make_map_index(Expression* map, Expression* index,
-                          source_location location)
+                          Location location)
 {
   return new Map_index_expression(map, index, location);
 }
@@ -10999,7 +11330,7 @@ Field_reference_expression::do_dump_expression(
 
 Field_reference_expression*
 Expression::make_field_reference(Expression* expr, unsigned int field_index,
-                                source_location location)
+                                Location location)
 {
   return new Field_reference_expression(expr, field_index, location);
 }
@@ -11156,7 +11487,7 @@ Interface_field_reference_expression::do_dump_expression(
 Expression*
 Expression::make_interface_field_reference(Expression* expr,
                                           const std::string& field,
-                                          source_location location)
+                                          Location location)
 {
   return new Interface_field_reference_expression(expr, field, location);
 }
@@ -11168,7 +11499,7 @@ class Selector_expression : public Parser_expression
 {
  public:
   Selector_expression(Expression* left, const std::string& name,
-                     source_location location)
+                     Location location)
     : Parser_expression(EXPRESSION_SELECTOR, location),
       left_(left), name_(name)
   { }
@@ -11221,7 +11552,7 @@ Selector_expression::do_lower(Gogo* gogo, Named_object*, Statement_inserter*,
 Expression*
 Selector_expression::lower_method_expression(Gogo* gogo)
 {
-  source_location location = this->location();
+  Location location = this->location();
   Type* type = this->left_->type();
   const std::string& name(this->name_);
 
@@ -11426,7 +11757,7 @@ Selector_expression::do_dump_expression(Ast_dump_context* ast_dump_context)
 
 Expression*
 Expression::make_selector(Expression* left, const std::string& name,
-                         source_location location)
+                         Location location)
 {
   return new Selector_expression(left, name, location);
 }
@@ -11436,7 +11767,7 @@ Expression::make_selector(Expression* left, const std::string& name,
 class Allocation_expression : public Expression
 {
  public:
-  Allocation_expression(Type* type, source_location location)
+  Allocation_expression(Type* type, Location location)
     : Expression(EXPRESSION_ALLOCATION, location),
       type_(type)
   { }
@@ -11499,7 +11830,7 @@ Allocation_expression::do_dump_expression(Ast_dump_context* ast_dump_context)
 // Make an allocation expression.
 
 Expression*
-Expression::make_allocation(Type* type, source_location location)
+Expression::make_allocation(Type* type, Location location)
 {
   return new Allocation_expression(type, location);
 }
@@ -11510,7 +11841,7 @@ class Struct_construction_expression : public Expression
 {
  public:
   Struct_construction_expression(Type* type, Expression_list* vals,
-                                source_location location)
+                                Location location)
     : Expression(EXPRESSION_STRUCT_CONSTRUCTION, location),
       type_(type), vals_(vals)
   { }
@@ -11781,7 +12112,7 @@ Struct_construction_expression::do_dump_expression(
 
 Expression*
 Expression::make_struct_composite_literal(Type* type, Expression_list* vals,
-                                         source_location location)
+                                         Location location)
 {
   go_assert(type->struct_type() != NULL);
   return new Struct_construction_expression(type, vals, location);
@@ -11796,7 +12127,7 @@ class Array_construction_expression : public Expression
  protected:
   Array_construction_expression(Expression_classification classification,
                                Type* type, Expression_list* vals,
-                               source_location location)
+                               Location location)
     : Expression(classification, location),
       type_(type), vals_(vals)
   { }
@@ -12046,7 +12377,7 @@ class Fixed_array_construction_expression :
 {
  public:
   Fixed_array_construction_expression(Type* type, Expression_list* vals,
-                                     source_location location)
+                                     Location location)
     : Array_construction_expression(EXPRESSION_FIXED_ARRAY_CONSTRUCTION,
                                    type, vals, location)
   {
@@ -12104,7 +12435,7 @@ class Open_array_construction_expression : public Array_construction_expression
 {
  public:
   Open_array_construction_expression(Type* type, Expression_list* vals,
-                                    source_location location)
+                                    Location location)
     : Array_construction_expression(EXPRESSION_OPEN_ARRAY_CONSTRUCTION,
                                    type, vals, location)
   {
@@ -12195,7 +12526,7 @@ Open_array_construction_expression::do_get_tree(Translate_context* context)
 
   if (is_constant_initializer)
     {
-      tree tmp = build_decl(this->location(), VAR_DECL,
+      tree tmp = build_decl(this->location().gcc_location(), VAR_DECL,
                            create_tmp_var_name("C"), TREE_TYPE(values));
       DECL_EXTERNAL(tmp) = 0;
       TREE_PUBLIC(tmp) = 0;
@@ -12231,7 +12562,8 @@ Open_array_construction_expression::do_get_tree(Translate_context* context)
       space = save_expr(space);
 
       tree s = fold_convert(build_pointer_type(TREE_TYPE(values)), space);
-      tree ref = build_fold_indirect_ref_loc(this->location(), s);
+      tree ref = build_fold_indirect_ref_loc(this->location().gcc_location(),
+                                             s);
       TREE_THIS_NOTRAP(ref) = 1;
       set = build2(MODIFY_EXPR, void_type_node, ref, values);
     }
@@ -12280,7 +12612,7 @@ Open_array_construction_expression::do_get_tree(Translate_context* context)
 
 Expression*
 Expression::make_slice_composite_literal(Type* type, Expression_list* vals,
-                                        source_location location)
+                                        Location location)
 {
   go_assert(type->is_slice_type());
   return new Open_array_construction_expression(type, vals, location);
@@ -12292,7 +12624,7 @@ class Map_construction_expression : public Expression
 {
  public:
   Map_construction_expression(Type* type, Expression_list* vals,
-                             source_location location)
+                             Location location)
     : Expression(EXPRESSION_MAP_CONSTRUCTION, location),
       type_(type), vals_(vals)
   { go_assert(vals == NULL || vals->size() % 2 == 0); }
@@ -12409,7 +12741,7 @@ tree
 Map_construction_expression::do_get_tree(Translate_context* context)
 {
   Gogo* gogo = context->gogo();
-  source_location loc = this->location();
+  Location loc = this->location();
 
   Map_type* mt = this->type_->map_type();
 
@@ -12421,7 +12753,8 @@ Map_construction_expression::do_get_tree(Translate_context* context)
   tree key_type_tree = type_to_tree(key_type->get_backend(gogo));
   if (key_type_tree == error_mark_node)
     return error_mark_node;
-  tree key_field = build_decl(loc, FIELD_DECL, id, key_type_tree);
+  tree key_field = build_decl(loc.gcc_location(), FIELD_DECL, id,
+                              key_type_tree);
   DECL_CONTEXT(key_field) = struct_type;
   TYPE_FIELDS(struct_type) = key_field;
 
@@ -12430,7 +12763,8 @@ Map_construction_expression::do_get_tree(Translate_context* context)
   tree val_type_tree = type_to_tree(val_type->get_backend(gogo));
   if (val_type_tree == error_mark_node)
     return error_mark_node;
-  tree val_field = build_decl(loc, FIELD_DECL, id, val_type_tree);
+  tree val_field = build_decl(loc.gcc_location(), FIELD_DECL, id,
+                              val_type_tree);
   DECL_CONTEXT(val_field) = struct_type;
   DECL_CHAIN(key_field) = val_field;
 
@@ -12502,19 +12836,21 @@ Map_construction_expression::do_get_tree(Translate_context* context)
        {
          tmp = create_tmp_var(array_type, get_name(array_type));
          DECL_INITIAL(tmp) = init;
-         make_tmp = fold_build1_loc(loc, DECL_EXPR, void_type_node, tmp);
+         make_tmp = fold_build1_loc(loc.gcc_location(), DECL_EXPR,
+                                     void_type_node, tmp);
          TREE_ADDRESSABLE(tmp) = 1;
        }
       else
        {
-         tmp = build_decl(loc, VAR_DECL, create_tmp_var_name("M"), array_type);
+         tmp = build_decl(loc.gcc_location(), VAR_DECL,
+                           create_tmp_var_name("M"), array_type);
          DECL_EXTERNAL(tmp) = 0;
          TREE_PUBLIC(tmp) = 0;
          TREE_STATIC(tmp) = 1;
          DECL_ARTIFICIAL(tmp) = 1;
          if (!TREE_CONSTANT(init))
-           make_tmp = fold_build2_loc(loc, INIT_EXPR, void_type_node, tmp,
-                                      init);
+           make_tmp = fold_build2_loc(loc.gcc_location(), INIT_EXPR,
+                                       void_type_node, tmp, init);
          else
            {
              TREE_READONLY(tmp) = 1;
@@ -12559,7 +12895,8 @@ Map_construction_expression::do_get_tree(Translate_context* context)
   if (make_tmp == NULL)
     ret = call;
   else
-    ret = fold_build2_loc(loc, COMPOUND_EXPR, type_tree, make_tmp, call);
+    ret = fold_build2_loc(loc.gcc_location(), COMPOUND_EXPR, type_tree,
+                          make_tmp, call);
   return ret;
 }
 
@@ -12598,7 +12935,7 @@ class Composite_literal_expression : public Parser_expression
 {
  public:
   Composite_literal_expression(Type* type, int depth, bool has_keys,
-                              Expression_list* vals, source_location location)
+                              Expression_list* vals, Location location)
     : Parser_expression(EXPRESSION_COMPOSITE_LITERAL, location),
       type_(type), depth_(depth), vals_(vals), has_keys_(has_keys)
   { }
@@ -12629,10 +12966,10 @@ class Composite_literal_expression : public Parser_expression
   lower_struct(Gogo*, Type*);
 
   Expression*
-  lower_array(Type*);
+  lower_array(Gogo*, Type*);
 
   Expression*
-  make_array(Type*, Expression_list*);
+  make_array(Gogo*, Type*, Expression_list*);
 
   Expression*
   lower_map(Gogo*, Named_object*, Statement_inserter*, Type*);
@@ -12685,14 +13022,23 @@ Composite_literal_expression::do_lower(Gogo* gogo, Named_object* function,
        }
     }
 
+  Type *pt = type->points_to();
+  bool is_pointer = false;
+  if (pt != NULL)
+    {
+      is_pointer = true;
+      type = pt;
+    }
+
+  Expression* ret;
   if (type->is_error())
     return Expression::make_error(this->location());
   else if (type->struct_type() != NULL)
-    return this->lower_struct(gogo, type);
+    ret = this->lower_struct(gogo, type);
   else if (type->array_type() != NULL)
-    return this->lower_array(type);
+    ret = this->lower_array(gogo, type);
   else if (type->map_type() != NULL)
-    return this->lower_map(gogo, function, inserter, type);
+    ret = this->lower_map(gogo, function, inserter, type);
   else
     {
       error_at(this->location(),
@@ -12700,6 +13046,11 @@ Composite_literal_expression::do_lower(Gogo* gogo, Named_object* function,
                "for composite literal"));
       return Expression::make_error(this->location());
     }
+
+  if (is_pointer)
+    ret = Expression::make_heap_composite(ret, this->location());
+
+  return ret;
 }
 
 // Lower a struct composite literal.
@@ -12707,10 +13058,29 @@ Composite_literal_expression::do_lower(Gogo* gogo, Named_object* function,
 Expression*
 Composite_literal_expression::lower_struct(Gogo* gogo, Type* type)
 {
-  source_location location = this->location();
+  Location location = this->location();
   Struct_type* st = type->struct_type();
   if (this->vals_ == NULL || !this->has_keys_)
-    return new Struct_construction_expression(type, this->vals_, location);
+    {
+      if (this->vals_ != NULL
+         && !this->vals_->empty()
+         && type->named_type() != NULL
+         && type->named_type()->named_object()->package() != NULL)
+       {
+         for (Struct_field_list::const_iterator pf = st->fields()->begin();
+              pf != st->fields()->end();
+              ++pf)
+           {
+             if (Gogo::is_hidden_name(pf->field_name()))
+               error_at(this->location(),
+                        "assignment of unexported field %qs in %qs literal",
+                        Gogo::message_name(pf->field_name()).c_str(),
+                        type->named_type()->message_name().c_str());
+           }
+       }
+
+      return new Struct_construction_expression(type, this->vals_, location);
+    }
 
   size_t field_count = st->field_count();
   std::vector<Expression*> vals(field_count);
@@ -12857,6 +13227,14 @@ Composite_literal_expression::lower_struct(Gogo* gogo, Type* type)
          return Expression::make_error(location);
        }
 
+      if (type->named_type() != NULL
+         && type->named_type()->named_object()->package() != NULL
+         && Gogo::is_hidden_name(sf->field_name()))
+       error_at(name_expr->location(),
+                "assignment of unexported field %qs in %qs literal",
+                Gogo::message_name(sf->field_name()).c_str(),
+                type->named_type()->message_name().c_str());
+
       vals[index] = val;
     }
 
@@ -12871,11 +13249,11 @@ Composite_literal_expression::lower_struct(Gogo* gogo, Type* type)
 // Lower an array composite literal.
 
 Expression*
-Composite_literal_expression::lower_array(Type* type)
+Composite_literal_expression::lower_array(Gogo* gogo, Type* type)
 {
-  source_location location = this->location();
+  Location location = this->location();
   if (this->vals_ == NULL || !this->has_keys_)
-    return this->make_array(type, this->vals_);
+    return this->make_array(gogo, type, this->vals_);
 
   std::vector<Expression*> vals;
   vals.reserve(this->vals_->size());
@@ -12975,16 +13353,17 @@ Composite_literal_expression::lower_array(Type* type)
   for (size_t i = 0; i < size; ++i)
     list->push_back(vals[i]);
 
-  return this->make_array(type, list);
+  return this->make_array(gogo, type, list);
 }
 
 // Actually build the array composite literal. This handles
 // [...]{...}.
 
 Expression*
-Composite_literal_expression::make_array(Type* type, Expression_list* vals)
+Composite_literal_expression::make_array(Gogo* gogo, Type* type,
+                                        Expression_list* vals)
 {
-  source_location location = this->location();
+  Location location = this->location();
   Array_type* at = type->array_type();
   if (at->length() != NULL && at->length()->is_nil_expression())
     {
@@ -12994,6 +13373,10 @@ Composite_literal_expression::make_array(Type* type, Expression_list* vals)
       Expression* elen = Expression::make_integer(&vlen, NULL, location);
       mpz_clear(vlen);
       at = Type::make_array_type(at->element_type(), elen);
+
+      // This is after the finalize_methods pass, so run that now.
+      at->finalize_methods(gogo);
+
       type = at;
     }
   if (at->length() != NULL)
@@ -13009,7 +13392,7 @@ Composite_literal_expression::lower_map(Gogo* gogo, Named_object* function,
                                        Statement_inserter* inserter,
                                        Type* type)
 {
-  source_location location = this->location();
+  Location location = this->location();
   if (this->vals_ != NULL)
     {
       if (!this->has_keys_)
@@ -13063,7 +13446,7 @@ Composite_literal_expression::do_dump_expression(
 Expression*
 Expression::make_composite_literal(Type* type, int depth, bool has_keys,
                                   Expression_list* vals,
-                                  source_location location)
+                                  Location location)
 {
   return new Composite_literal_expression(type, depth, has_keys, vals,
                                          location);
@@ -13247,7 +13630,7 @@ Type_guard_expression::do_dump_expression(Ast_dump_context* ast_dump_context)
 
 Expression*
 Expression::make_type_guard(Expression* expr, Type* type,
-                           source_location location)
+                           Location location)
 {
   return new Type_guard_expression(expr, type, location);
 }
@@ -13260,7 +13643,7 @@ Expression::make_type_guard(Expression* expr, Type* type,
 class Heap_composite_expression : public Expression
 {
  public:
-  Heap_composite_expression(Expression* expr, source_location location)
+  Heap_composite_expression(Expression* expr, Location location)
     : Expression(EXPRESSION_HEAP_COMPOSITE, location),
       expr_(expr)
   { }
@@ -13316,12 +13699,13 @@ Heap_composite_expression::do_get_tree(Translate_context* context)
                                                expr_size, this->location());
   space = fold_convert(build_pointer_type(TREE_TYPE(expr_tree)), space);
   space = save_expr(space);
-  tree ref = build_fold_indirect_ref_loc(this->location(), space);
+  tree ref = build_fold_indirect_ref_loc(this->location().gcc_location(),
+                                         space);
   TREE_THIS_NOTRAP(ref) = 1;
   tree ret = build2(COMPOUND_EXPR, TREE_TYPE(space),
                    build2(MODIFY_EXPR, void_type_node, ref, expr_tree),
                    space);
-  SET_EXPR_LOCATION(ret, this->location());
+  SET_EXPR_LOCATION(ret, this->location().gcc_location());
   return ret;
 }
 
@@ -13339,7 +13723,7 @@ Heap_composite_expression::do_dump_expression(
 // Allocate a composite literal on the heap.
 
 Expression*
-Expression::make_heap_composite(Expression* expr, source_location location)
+Expression::make_heap_composite(Expression* expr, Location location)
 {
   return new Heap_composite_expression(expr, location);
 }
@@ -13385,12 +13769,18 @@ Receive_expression::do_check_types(Gogo*)
 tree
 Receive_expression::do_get_tree(Translate_context* context)
 {
+  Location loc = this->location();
+
   Channel_type* channel_type = this->channel_->type()->channel_type();
   if (channel_type == NULL)
     {
       go_assert(this->channel_->type()->is_error());
       return error_mark_node;
     }
+
+  Expression* td = Expression::make_type_descriptor(channel_type, loc);
+  tree td_tree = td->get_tree(context);
+
   Type* element_type = channel_type->element_type();
   Btype* element_type_btype = element_type->get_backend(context->gogo());
   tree element_type_tree = type_to_tree(element_type_btype);
@@ -13399,8 +13789,7 @@ Receive_expression::do_get_tree(Translate_context* context)
   if (element_type_tree == error_mark_node || channel == error_mark_node)
     return error_mark_node;
 
-  return Gogo::receive_from_channel(element_type_tree, channel,
-                                   this->for_select_, this->location());
+  return Gogo::receive_from_channel(element_type_tree, td_tree, channel, loc);
 }
 
 // Dump ast representation for a receive expression.
@@ -13415,7 +13804,7 @@ Receive_expression::do_dump_expression(Ast_dump_context* ast_dump_context) const
 // Make a receive expression.
 
 Receive_expression*
-Expression::make_receive(Expression* channel, source_location location)
+Expression::make_receive(Expression* channel, Location location)
 {
   return new Receive_expression(channel, location);
 }
@@ -13426,7 +13815,7 @@ Expression::make_receive(Expression* channel, source_location location)
 class Type_descriptor_expression : public Expression
 {
  public:
-  Type_descriptor_expression(Type* type, source_location location)
+  Type_descriptor_expression(Type* type, Location location)
     : Expression(EXPRESSION_TYPE_DESCRIPTOR, location),
       type_(type)
   { }
@@ -13471,7 +13860,7 @@ Type_descriptor_expression::do_dump_expression(
 // Make a type descriptor expression.
 
 Expression*
-Expression::make_type_descriptor(Type* type, source_location location)
+Expression::make_type_descriptor(Type* type, Location location)
 {
   return new Type_descriptor_expression(type, location);
 }
@@ -13486,7 +13875,7 @@ class Type_info_expression : public Expression
 {
  public:
   Type_info_expression(Type* type, Type_info type_info)
-    : Expression(EXPRESSION_TYPE_INFO, BUILTINS_LOCATION),
+    : Expression(EXPRESSION_TYPE_INFO, Linemap::predeclared_location()),
       type_(type), type_info_(type_info)
   { }
 
@@ -13538,25 +13927,26 @@ Type_info_expression::do_type()
 tree
 Type_info_expression::do_get_tree(Translate_context* context)
 {
-  tree type_tree = type_to_tree(this->type_->get_backend(context->gogo()));
-  if (type_tree == error_mark_node)
-    return error_mark_node;
-
-  tree val_type_tree = type_to_tree(this->type()->get_backend(context->gogo()));
-  go_assert(val_type_tree != error_mark_node);
-
-  if (this->type_info_ == TYPE_INFO_SIZE)
-    return fold_convert_loc(BUILTINS_LOCATION, val_type_tree,
-                           TYPE_SIZE_UNIT(type_tree));
-  else
+  Btype* btype = this->type_->get_backend(context->gogo());
+  Gogo* gogo = context->gogo();
+  size_t val;
+  switch (this->type_info_)
     {
-      unsigned int val;
-      if (this->type_info_ == TYPE_INFO_ALIGNMENT)
-       val = go_type_alignment(type_tree);
-      else
-       val = go_field_alignment(type_tree);
-      return build_int_cstu(val_type_tree, val);
+    case TYPE_INFO_SIZE:
+      val = gogo->backend()->type_size(btype);
+      break;
+    case TYPE_INFO_ALIGNMENT:
+      val = gogo->backend()->type_alignment(btype);
+      break;
+    case TYPE_INFO_FIELD_ALIGNMENT:
+      val = gogo->backend()->type_field_alignment(btype);
+      break;
+    default:
+      go_unreachable();
     }
+  tree val_type_tree = type_to_tree(this->type()->get_backend(gogo));
+  go_assert(val_type_tree != error_mark_node);
+  return build_int_cstu(val_type_tree, val);
 }
 
 // Dump ast representation for a type info expression.
@@ -13592,7 +13982,8 @@ class Struct_field_offset_expression : public Expression
 {
  public:
   Struct_field_offset_expression(Struct_type* type, const Struct_field* field)
-    : Expression(EXPRESSION_STRUCT_FIELD_OFFSET, BUILTINS_LOCATION),
+    : Expression(EXPRESSION_STRUCT_FIELD_OFFSET,
+                Linemap::predeclared_location()),
       type_(type), field_(field)
   { }
 
@@ -13680,7 +14071,7 @@ Expression::make_struct_field_offset(Struct_type* type,
 class Map_descriptor_expression : public Expression
 {
  public:
-  Map_descriptor_expression(Map_type* type, source_location location)
+  Map_descriptor_expression(Map_type* type, Location location)
     : Expression(EXPRESSION_MAP_DESCRIPTOR, location),
       type_(type)
   { }
@@ -13727,7 +14118,7 @@ Map_descriptor_expression::do_dump_expression(
 // Make a map descriptor expression.
 
 Expression*
-Expression::make_map_descriptor(Map_type* type, source_location location)
+Expression::make_map_descriptor(Map_type* type, Location location)
 {
   return new Map_descriptor_expression(type, location);
 }
@@ -13737,7 +14128,7 @@ Expression::make_map_descriptor(Map_type* type, source_location location)
 class Label_addr_expression : public Expression
 {
  public:
-  Label_addr_expression(Label* label, source_location location)
+  Label_addr_expression(Label* label, Location location)
     : Expression(EXPRESSION_LABEL_ADDR, location),
       label_(label)
   { }
@@ -13773,7 +14164,7 @@ class Label_addr_expression : public Expression
 // Make an expression for the address of an unnamed label.
 
 Expression*
-Expression::make_label_addr(Label* label, source_location location)
+Expression::make_label_addr(Label* label, Location location)
 {
   return new Label_addr_expression(label, location);
 }