diff mbox

Go patch committed: Simplify making a constant integer expression

Message ID CAOyqgcUf7k0jbWdC+=v1o5rXRMgvRuw28+ES4_Xi6xgbo1_KHQ@mail.gmail.com
State New
Headers show

Commit Message

Ian Lance Taylor Oct. 24, 2014, 1:49 a.m. UTC
The Go frontend currently only makes integer expressions using the
mpz_t type, which is awkward when building an expression for a
constant or other ordinary C integer.  This patch adds a couple of
helper functions and changes the frontend to use them.  Bootstrapped
and ran Go testsuite on x86_64-unknown-linux-gnu.  Committed to
mainline.

Ian
diff mbox

Patch

diff -r 6887e559501c go/expressions.cc
--- a/go/expressions.cc	Tue Oct 21 08:59:11 2014 -0700
+++ b/go/expressions.cc	Thu Oct 23 18:43:32 2014 -0700
@@ -157,11 +157,8 @@ 
   else if (lhs_type->is_slice_type() && rhs_type->is_nil_type())
     {
       // Assigning nil to a slice.
-      mpz_t zval;
-      mpz_init_set_ui(zval, 0UL);
-      Expression* zero = Expression::make_integer(&zval, NULL, location);
-      mpz_clear(zval);
       Expression* nil = Expression::make_nil(location);
+      Expression* zero = Expression::make_integer_ul(0, NULL, location);
       return Expression::make_slice_value(lhs_type, nil, zero, zero, location);
     }
   else if (rhs_type->is_nil_type())
@@ -491,11 +488,7 @@ 
   Expression* index_overflows = Expression::make_boolean(false, loc);
   if (!val_is_unsigned)
     {
-      mpz_t zval;
-      mpz_init_set_ui(zval, 0UL);
-      Expression* zero = Expression::make_integer(&zval, val_type, loc);
-      mpz_clear(zval);
-
+      Expression* zero = Expression::make_integer_ul(0, val_type, loc);
       negative_index = Expression::make_binary(OPERATOR_LT, val, zero, loc);
     }
 
@@ -512,7 +505,7 @@ 
       mpz_init(maxval);
       mpz_mul_2exp(maxval, one, bound_type_size - 1);
       mpz_sub_ui(maxval, maxval, 1);
-      Expression* max = Expression::make_integer(&maxval, val_type, loc);
+      Expression* max = Expression::make_integer_z(&maxval, val_type, loc);
       mpz_clear(one);
       mpz_clear(maxval);
 
@@ -1824,8 +1817,8 @@ 
       return Expression::make_character(&this->val_, this->type_,
 					this->location());
     else
-      return Expression::make_integer(&this->val_, this->type_,
-				      this->location());
+      return Expression::make_integer_z(&this->val_, this->type_,
+					this->location());
   }
 
   void
@@ -2047,7 +2040,7 @@ 
       if (is_character_constant)
 	ret = Expression::make_character(&val, NULL, imp->location());
       else
-	ret = Expression::make_integer(&val, NULL, imp->location());
+	ret = Expression::make_integer_z(&val, NULL, imp->location());
       mpz_clear(val);
       return ret;
     }
@@ -2077,14 +2070,38 @@ 
     ast_dump_context->ostream() << '\'';
 }
 
-// Build a new integer value.
-
-Expression*
-Expression::make_integer(const mpz_t* val, Type* type, Location location)
+// Build a new integer value from a multi-precision integer.
+
+Expression*
+Expression::make_integer_z(const mpz_t* val, Type* type, Location location)
 {
   return new Integer_expression(val, type, false, location);
 }
 
+// Build a new integer value from an unsigned long.
+
+Expression*
+Expression::make_integer_ul(unsigned long val, Type *type, Location location)
+{
+  mpz_t zval;
+  mpz_init_set_ui(zval, val);
+  Expression* ret = Expression::make_integer_z(&zval, type, location);
+  mpz_clear(zval);
+  return ret;
+}
+
+// Build a new integer value from a signed long.
+
+Expression*
+Expression::make_integer_sl(long val, Type *type, Location location)
+{
+  mpz_t zval;
+  mpz_init_set_si(zval, val);
+  Expression* ret = Expression::make_integer_z(&zval, type, location);
+  mpz_clear(zval);
+  return ret;
+}
+
 // Build a new character constant value.
 
 Expression*
@@ -2593,12 +2610,7 @@ 
 		   "iota is only defined in const declarations");
 	  iota_value = 0;
 	}
-      mpz_t val;
-      mpz_init_set_ui(val, static_cast<unsigned long>(iota_value));
-      Expression* ret = Expression::make_integer(&val, NULL,
-						 this->location());
-      mpz_clear(val);
-      return ret;
+      return Expression::make_integer_ul(iota_value, NULL, this->location());
     }
 
   // Make sure that the constant itself has been lowered.
@@ -3105,13 +3117,10 @@ 
 		       p != s.end();
 		       p++)
 		    {
-		      mpz_t val;
-		      mpz_init_set_ui(val, static_cast<unsigned char>(*p));
-		      Expression* v = Expression::make_integer(&val,
-							       element_type,
-							       location);
-		      vals->push_back(v);
-		      mpz_clear(val);
+		      unsigned char c = static_cast<unsigned char>(*p);
+		      vals->push_back(Expression::make_integer_ul(c,
+								  element_type,
+								  location));
 		    }
 		}
 	      else
@@ -3129,13 +3138,9 @@ 
 			  adv = 1;
 			}
 		      p += adv;
-		      mpz_t val;
-		      mpz_init_set_ui(val, c);
-		      Expression* v = Expression::make_integer(&val,
-							       element_type,
-							       location);
-		      vals->push_back(v);
-		      mpz_clear(val);
+		      vals->push_back(Expression::make_integer_ul(c,
+								  element_type,
+								  location));
 		    }
 		}
 
@@ -5419,12 +5424,7 @@ 
 					       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);
-
+  Expression* zero = Expression::make_integer_ul(0, NULL, loc);
   return Expression::make_binary(this->op_, call, zero, loc);
 }
 
@@ -5883,10 +5883,9 @@ 
 		  if (mpz_sgn(val) < 0)
 		    {
 		      this->report_error(_("negative shift count"));
-		      mpz_set_ui(val, 0);
 		      Location rloc = this->right_->location();
-		      this->right_ = Expression::make_integer(&val, right_type,
-							      rloc);
+		      this->right_ = Expression::make_integer_ul(0, right_type,
+								 rloc);
 		    }
 		  mpz_clear(val);
 		}
@@ -6343,10 +6342,7 @@ 
   Type* left_type = left->type();
   Type* right_type = right->type();
 
-  mpz_t zval;
-  mpz_init_set_ui(zval, 0UL);
-  Expression* zexpr = Expression::make_integer(&zval, NULL, location);
-  mpz_clear(zval);
+  Expression* zexpr = Expression::make_integer_ul(0, NULL, location);
 
   if (left_type->is_string_type() && right_type->is_string_type())
     {
@@ -7260,11 +7256,7 @@ 
 	  this->report_error(_("length required when allocating a slice"));
 	  return Expression::make_error(this->location());
 	}
-
-      mpz_t zval;
-      mpz_init_set_ui(zval, 0);
-      len_arg = Expression::make_integer(&zval, NULL, loc);
-      mpz_clear(zval);
+      len_arg = Expression::make_integer_ul(0, NULL, loc);
     }
   else
     {
@@ -8543,7 +8535,7 @@ 
         mpz_t ival;
         nc.get_int(&ival);
         Expression* int_cst =
-            Expression::make_integer(&ival, uintptr_type, location);
+            Expression::make_integer_z(&ival, uintptr_type, location);
         mpz_clear(ival);
         return int_cst->get_backend(context);
       }
@@ -8586,13 +8578,10 @@ 
 
 	Type* element_type = at->element_type();
 	Btype* element_btype = element_type->get_backend(gogo);
-
-        mpz_t size;
-        size_t element_size = gogo->backend()->type_size(element_btype);
-        mpz_init_set_ui(size, element_size);
-        Expression* size_expr = Expression::make_integer(&size, length->type(), location);
-        mpz_clear(size);
-
+	size_t element_size = gogo->backend()->type_size(element_btype);
+	Expression* size_expr = Expression::make_integer_ul(element_size,
+							    length->type(),
+							    location);
         Expression* bytecount =
             Expression::make_binary(OPERATOR_MULT, size_expr, length, location);
         Expression* copy = Runtime::make_call(Runtime::COPY, location, 3,
@@ -8615,7 +8604,7 @@ 
         go_assert(arg2->is_variable());
 	Expression* arg2_val;
 	Expression* arg2_len;
-        mpz_t size;
+	unsigned long size;
 	if (arg2->type()->is_string_type()
 	    && element_type->integer_type() != NULL
 	    && element_type->integer_type()->is_byte())
@@ -8624,19 +8613,17 @@ 
 						    location);
 	    arg2_len = Expression::make_string_info(arg2, STRING_INFO_LENGTH,
 						    location);
-            mpz_init_set_ui(size, 1UL);
+	    size = 1;
 	  }
 	else
 	  {
 	    arg2_val = at->get_value_pointer(gogo, arg2);
 	    arg2_len = at->get_length(gogo, arg2);
 	    Btype* element_btype = element_type->get_backend(gogo);
-            size_t element_size = gogo->backend()->type_size(element_btype);
-            mpz_init_set_ui(size, element_size);
+	    size = gogo->backend()->type_size(element_btype);
 	  }
         Expression* element_size =
-            Expression::make_integer(&size, NULL, location);
-        mpz_clear(size);
+	  Expression::make_integer_ul(size, NULL, location);
 
         Expression* append = Runtime::make_call(Runtime::APPEND, location, 4,
                                                 arg1, arg2_val, arg2_len,
@@ -10762,12 +10749,7 @@ 
 
   Expression* end = NULL;
   if (this->end_->is_nil_expression())
-    {
-      mpz_t neg_one;
-      mpz_init_set_si(neg_one, -1);
-      end = Expression::make_integer(&neg_one, int_type, loc);
-      mpz_clear(neg_one);
-    }
+    end = Expression::make_integer_sl(-1, int_type, loc);
   else
     {
       Expression* bounds_check = Expression::check_bounds(this->end_, loc);
@@ -11076,10 +11058,7 @@ 
   // string, it won't garbage collect the bytes.  So we use a
   // [...]byte.
 
-  mpz_t val;
-  mpz_init_set_ui(val, s.length());
-  Expression* length_expr = Expression::make_integer(&val, NULL, loc);
-  mpz_clear(val);
+  Expression* length_expr = Expression::make_integer_ul(s.length(), NULL, loc);
 
   Type* byte_type = gogo->lookup_global("byte")->type_value();
   Type* array_type = Type::make_array_type(byte_type, length_expr);
@@ -11087,10 +11066,8 @@ 
   Expression_list* bytes = new Expression_list();
   for (std::string::const_iterator p = s.begin(); p != s.end(); p++)
     {
-      mpz_init_set_ui(val, *p);
-      Expression* byte = Expression::make_integer(&val, NULL, loc);
-      mpz_clear(val);
-      bytes->push_back(byte);
+      unsigned char c = static_cast<unsigned char>(*p);
+      bytes->push_back(Expression::make_integer_ul(c, NULL, loc));
     }
 
   Expression* e = Expression::make_composite_literal(array_type, 0, false,
@@ -12490,20 +12467,19 @@ 
   {
     go_assert(type->is_slice_type());
 
-    mpz_t lenval;
+    unsigned long lenval;
     Expression* length;
     if (vals == NULL || vals->empty())
-      mpz_init_set_ui(lenval, 0);
+      lenval = 0;
     else
       {
 	if (this->indexes() == NULL)
-	  mpz_init_set_ui(lenval, vals->size());
+	  lenval = vals->size();
 	else
-	  mpz_init_set_ui(lenval, indexes->back() + 1);
+	  lenval = indexes->back() + 1;
       }
     Type* int_type = Type::lookup_integer_type("int");
-    length = Expression::make_integer(&lenval, int_type, location);
-    mpz_clear(lenval);
+    length = Expression::make_integer_ul(lenval, int_type, location);
     Type* element_type = type->array_type()->element_type();
     this->valtype_ = Type::make_array_type(element_type, length);
   }
@@ -12722,11 +12698,7 @@ 
                                                         key_value_pair, loc));
         }
 
-      mpz_t lenval;
-      mpz_init_set_ui(lenval, i);
-      Expression* element_count = Expression::make_integer(&lenval, NULL, loc);
-      mpz_clear(lenval);
-
+      Expression* element_count = Expression::make_integer_ul(i, NULL, loc);
       Type* ctor_type =
           Type::make_array_type(this->element_type_, element_count);
       Expression* constructor =
@@ -12831,10 +12803,7 @@ 
   Expression* descriptor = Expression::make_map_descriptor(mt, loc);
 
   Type* uintptr_t = Type::lookup_integer_type("uintptr");
-  mpz_t countval;
-  mpz_init_set_ui(countval, i);
-  Expression* count = Expression::make_integer(&countval, uintptr_t, loc);
-  mpz_clear(countval);
+  Expression* count = Expression::make_integer_ul(i, uintptr_t, loc);
 
   Expression* entry_size =
       Expression::make_type_info(this->element_type_, TYPE_INFO_SIZE);
@@ -13463,10 +13432,7 @@ 
 	    }
 	}
 
-      mpz_t vlen;
-      mpz_init_set_ui(vlen, size);
-      Expression* elen = Expression::make_integer(&vlen, NULL, location);
-      mpz_clear(vlen);
+      Expression* elen = Expression::make_integer_ul(size, NULL, location);
       at = Type::make_array_type(at->element_type(), elen);
       type = at;
     }
@@ -14903,12 +14869,10 @@ 
   Btype* btype = this->type_->get_backend(gogo);
 
   size_t offset = gogo->backend()->type_field_offset(btype, i);
-  mpz_t offsetval;
-  mpz_init_set_ui(offsetval, offset);
   Type* uptr_type = Type::lookup_integer_type("uintptr");
-  Expression* ret = Expression::make_integer(&offsetval, uptr_type,
-					     Linemap::predeclared_location());
-  mpz_clear(offsetval);
+  Expression* ret =
+    Expression::make_integer_ul(offset, uptr_type,
+				Linemap::predeclared_location());
   return ret->get_backend(context);
 }
 
@@ -15980,7 +15944,7 @@ 
   switch (this->classification_)
     {
     case NC_INT:
-      return Expression::make_integer(&this->u_.int_val, this->type_, loc);
+      return Expression::make_integer_z(&this->u_.int_val, this->type_, loc);
     case NC_RUNE:
       return Expression::make_character(&this->u_.int_val, this->type_, loc);
     case NC_FLOAT:
diff -r 6887e559501c go/expressions.h
--- a/go/expressions.h	Tue Oct 21 08:59:11 2014 -0700
+++ b/go/expressions.h	Thu Oct 23 18:43:32 2014 -0700
@@ -214,10 +214,20 @@ 
   static Expression*
   make_character(const mpz_t*, Type*, Location);
 
-  // Make a constant integer expression.  TYPE should be NULL for an
-  // abstract type.
+  // Make a constant integer expression from a multi-precision
+  // integer.  TYPE should be NULL for an abstract type.
   static Expression*
-  make_integer(const mpz_t*, Type*, Location);
+  make_integer_z(const mpz_t*, Type*, Location);
+
+  // Make a constant integer expression from an unsigned long.  TYPE
+  // should be NULL for an abstract type.
+  static Expression*
+  make_integer_ul(unsigned long, Type*, Location);
+
+  // Make a constant integer expression from a signed long.  TYPE
+  // should be NULL for an abstract type.
+  static Expression*
+  make_integer_sl(long, Type*, Location);
 
   // Make a constant float expression.  TYPE should be NULL for an
   // abstract type.
diff -r 6887e559501c go/gogo.cc
--- a/go/gogo.cc	Tue Oct 21 08:59:11 2014 -0700
+++ b/go/gogo.cc	Thu Oct 23 18:43:32 2014 -0700
@@ -587,11 +587,7 @@ 
       // We will change the type later, when we know the size.
       Type* byte_type = this->lookup_global("byte")->type_value();
 
-      mpz_t val;
-      mpz_init_set_ui(val, 0);
-      Expression* zero = Expression::make_integer(&val, NULL, bloc);
-      mpz_clear(val);
-
+      Expression* zero = Expression::make_integer_ul(0, NULL, bloc);
       Type* array_type = Type::make_array_type(byte_type, zero);
 
       Variable* var = new Variable(array_type, NULL, true, false, false, bloc);
@@ -738,11 +734,8 @@ 
                                                           "__size", uint_type);
 
   Location builtin_loc = Linemap::predeclared_location();
-  size_t count = var_gc.size();
-  mpz_t lenval;
-  mpz_init_set_ui(lenval, count);
-  Expression* length = Expression::make_integer(&lenval, NULL, builtin_loc);
-  mpz_clear(lenval);
+  Expression* length = Expression::make_integer_ul(var_gc.size(), NULL,
+						   builtin_loc);
 
   Array_type* root_array_type = Type::make_array_type(root_type, length);
   Type* ptdt = Type::make_type_descriptor_ptr_type();
@@ -783,10 +776,7 @@ 
   Expression* nil = Expression::make_nil(builtin_loc);
   null_init->push_back(nil);
 
-  mpz_t zval;
-  mpz_init_set_ui(zval, 0UL);
-  Expression* zero = Expression::make_integer(&zval, NULL, builtin_loc);
-  mpz_clear(zval);
+  Expression *zero = Expression::make_integer_ul(0, NULL, builtin_loc);
   null_init->push_back(zero);
 
   Expression* null_root_ctor =
@@ -4029,10 +4019,7 @@ 
   Expression* fn = Expression::make_func_reference(builtin_return_address,
 						   NULL, location);
 
-  mpz_t zval;
-  mpz_init_set_ui(zval, 0UL);
-  Expression* zexpr = Expression::make_integer(&zval, NULL, location);
-  mpz_clear(zval);
+  Expression* zexpr = Expression::make_integer_ul(0, NULL, location);
   Expression_list *args = new Expression_list();
   args->push_back(zexpr);
 
@@ -4067,10 +4054,8 @@ 
 Gogo::runtime_error(int code, Location location)
 {
   Type* int32_type = Type::lookup_integer_type("int32");
-  mpz_t val;
-  mpz_init_set_ui(val, code);
-  Expression* code_expr = Expression::make_integer(&val, int32_type, location);
-  mpz_clear(val);
+  Expression* code_expr = Expression::make_integer_ul(code, int32_type,
+						      location);
   return Runtime::make_call(Runtime::RUNTIME_ERROR, location, 1, code_expr);
 }
 
diff -r 6887e559501c go/parse.cc
--- a/go/parse.cc	Tue Oct 21 08:59:11 2014 -0700
+++ b/go/parse.cc	Thu Oct 23 18:43:32 2014 -0700
@@ -2510,8 +2510,8 @@ 
       return ret;
 
     case Token::TOKEN_INTEGER:
-      ret = Expression::make_integer(token->integer_value(), NULL,
-				     token->location());
+      ret = Expression::make_integer_z(token->integer_value(), NULL,
+				       token->location());
       this->advance_token();
       return ret;
 
@@ -3129,12 +3129,7 @@ 
   if (!this->peek_token()->is_op(OPERATOR_COLON))
     start = this->expression(PRECEDENCE_NORMAL, false, true, NULL, NULL);
   else
-    {
-      mpz_t zero;
-      mpz_init_set_ui(zero, 0);
-      start = Expression::make_integer(&zero, NULL, location);
-      mpz_clear(zero);
-    }
+    start = Expression::make_integer_ul(0, NULL, location);
 
   Expression* end = NULL;
   if (this->peek_token()->is_op(OPERATOR_COLON))
diff -r 6887e559501c go/runtime.cc
--- a/go/runtime.cc	Tue Oct 21 08:59:11 2014 -0700
+++ b/go/runtime.cc	Thu Oct 23 18:43:32 2014 -0700
@@ -397,12 +397,8 @@ 
 Runtime::map_iteration_type()
 {
   const unsigned long map_iteration_size = 4;
-
-  mpz_t ival;
-  mpz_init_set_ui(ival, map_iteration_size);
-  Expression* iexpr = Expression::make_integer(&ival, NULL,
-                                               Linemap::predeclared_location());
-  mpz_clear(ival);
-
+  Expression* iexpr =
+    Expression::make_integer_ul(map_iteration_size, NULL,
+				Linemap::predeclared_location());
   return Type::make_array_type(runtime_function_type(RFT_POINTER), iexpr);
 }
diff -r 6887e559501c go/statements.cc
--- a/go/statements.cc	Tue Oct 21 08:59:11 2014 -0700
+++ b/go/statements.cc	Thu Oct 23 18:43:32 2014 -0700
@@ -1838,12 +1838,7 @@ 
 Inc_dec_statement::do_lower(Gogo*, Named_object*, Block*, Statement_inserter*)
 {
   Location loc = this->location();
-
-  mpz_t oval;
-  mpz_init_set_ui(oval, 1UL);
-  Expression* oexpr = Expression::make_integer(&oval, this->expr_->type(), loc);
-  mpz_clear(oval);
-
+  Expression* oexpr = Expression::make_integer_ul(1, this->expr_->type(), loc);
   Operator op = this->is_inc_ ? OPERATOR_PLUSEQ : OPERATOR_MINUSEQ;
   return Statement::make_assignment_operation(op, this->expr_, oexpr, loc);
 }
@@ -3441,7 +3436,7 @@ 
 		  continue;
 		}
 	      go_assert(nc.type() != NULL);
-	      e = Expression::make_integer(&ival, nc.type(), e->location());
+	      e = Expression::make_integer_z(&ival, nc.type(), e->location());
 	      mpz_clear(ival);
 	    }
 
@@ -4559,10 +4554,8 @@ 
 
   Expression* selref = Expression::make_temporary_reference(sel, loc);
 
-  mpz_t ival;
-  mpz_init_set_ui(ival, this->index_);
-  Expression* index_expr = Expression::make_integer(&ival, NULL, loc);
-  mpz_clear(ival);
+  Expression* index_expr = Expression::make_integer_ul(this->index_, NULL,
+						       loc);
 
   if (this->is_default_)
     {
@@ -4907,11 +4900,8 @@ 
        ++p, ++i)
     {
       int index = p->index();
-      mpz_t ival;
-      mpz_init_set_ui(ival, index);
-      Expression* index_expr = Expression::make_integer(&ival, int32_type,
-							location);
-      mpz_clear(ival);
+      Expression* index_expr = Expression::make_integer_ul(index, int32_type,
+							   location);
       cases[i].push_back(index_expr->get_backend(context));
 
       Bstatement* s = p->get_statements_backend(context);
@@ -4993,11 +4983,8 @@ 
 
   go_assert(this->sel_ == NULL);
 
-  mpz_t ival;
-  mpz_init_set_ui(ival, this->clauses_->size());
-  Expression* size_expr = Expression::make_integer(&ival, NULL, loc);
-  mpz_clear(ival);
-
+  Expression* size_expr = Expression::make_integer_ul(this->clauses_->size(),
+						      NULL, loc);
   Expression* call = Runtime::make_call(Runtime::NEWSELECT, loc, 1, size_expr);
 
   this->sel_ = Statement::make_temporary(NULL, call, loc);
@@ -5488,10 +5475,7 @@ 
 							    len_call, loc);
   init->add_statement(len_temp);
 
-  mpz_t zval;
-  mpz_init_set_ui(zval, 0UL);
-  Expression* zexpr = Expression::make_integer(&zval, NULL, loc);
-  mpz_clear(zval);
+  Expression* zexpr = Expression::make_integer_ul(0, NULL, loc);
 
   Temporary_reference_expression* tref =
     Expression::make_temporary_reference(index_temp, loc);
@@ -5589,10 +5573,7 @@ 
 							    len_call, loc);
   init->add_statement(len_temp);
 
-  mpz_t zval;
-  mpz_init_set_ui(zval, 0UL);
-  Expression* zexpr = Expression::make_integer(&zval, NULL, loc);
-  mpz_clear(zval);
+  Expression* zexpr = Expression::make_integer_ul(0, NULL, loc);
 
   Temporary_reference_expression* tref =
     Expression::make_temporary_reference(index_temp, loc);
@@ -5681,9 +5662,7 @@ 
     Statement::make_temporary(index_temp->type(), NULL, loc);
   init->add_statement(next_index_temp);
 
-  mpz_t zval;
-  mpz_init_set_ui(zval, 0UL);
-  Expression* zexpr = Expression::make_integer(&zval, NULL, loc);
+  Expression* zexpr = Expression::make_integer_ul(0, NULL, loc);
 
   Temporary_reference_expression* ref =
     Expression::make_temporary_reference(index_temp, loc);
@@ -5742,8 +5721,7 @@ 
   iter_init->add_statement(s);
 
   ref = Expression::make_temporary_reference(next_index_temp, loc);
-  zexpr = Expression::make_integer(&zval, NULL, loc);
-  mpz_clear(zval);
+  zexpr = Expression::make_integer_ul(0, NULL, loc);
   Expression* equals = Expression::make_binary(OPERATOR_EQEQ, ref, zexpr, loc);
 
   Block* then_block = new Block(iter_init, loc);
@@ -5823,18 +5801,11 @@ 
   //   hiter[0] != nil
 
   ref = Expression::make_temporary_reference(hiter, loc);
-
-  mpz_t zval;
-  mpz_init_set_ui(zval, 0UL);
-  Expression* zexpr = Expression::make_integer(&zval, NULL, loc);
-  mpz_clear(zval);
-
+  Expression* zexpr = Expression::make_integer_ul(0, NULL, loc);
   Expression* index = Expression::make_index(ref, zexpr, NULL, NULL, loc);
-
   Expression* ne = Expression::make_binary(OPERATOR_NOTEQ, index,
 					   Expression::make_nil(loc),
 					   loc);
-
   *pcond = ne;
 
   // Set *PITER_INIT to
diff -r 6887e559501c go/types.cc
--- a/go/types.cc	Tue Oct 21 08:59:11 2014 -0700
+++ b/go/types.cc	Thu Oct 23 18:43:32 2014 -0700
@@ -1956,9 +1956,8 @@ 
     runtime_type_kind |= RUNTIME_TYPE_KIND_NO_POINTERS;
   Struct_field_list::const_iterator p = fields->begin();
   go_assert(p->is_field_name("kind"));
-  mpz_t iv;
-  mpz_init_set_ui(iv, runtime_type_kind);
-  vals->push_back(Expression::make_integer(&iv, p->type(), bloc));
+  vals->push_back(Expression::make_integer_ul(runtime_type_kind, p->type(),
+					      bloc));
 
   ++p;
   go_assert(p->is_field_name("align"));
@@ -1982,8 +1981,7 @@ 
     h = name->hash_for_method(gogo);
   else
     h = this->hash_for_method(gogo);
-  mpz_set_ui(iv, h);
-  vals->push_back(Expression::make_integer(&iv, p->type(), bloc));
+  vals->push_back(Expression::make_integer_ul(h, p->type(), bloc));
 
   ++p;
   go_assert(p->is_field_name("hashfn"));
@@ -2048,8 +2046,6 @@ 
   ++p;
   go_assert(p == fields->end());
 
-  mpz_clear(iv);
-
   return Expression::make_struct_composite_literal(td_type, vals, bloc);
 }
 
@@ -2172,23 +2168,14 @@ 
   vals->push_back(Expression::make_type_info(this,
 					     Expression::TYPE_INFO_SIZE));
 
-  mpz_t off;
-  mpz_init_set_ui(off, 0UL);
-  Expression* offset = Expression::make_integer(&off, uintptr_t, bloc);
-  mpz_clear(off);
+  Expression* offset = Expression::make_integer_ul(0, uintptr_t, bloc);
 
   this->do_gc_symbol(gogo, &vals, &offset, 0);
 
-  mpz_t end;
-  mpz_init_set_ui(end, GC_END);
-  vals->push_back(Expression::make_integer(&end, uintptr_t, bloc));
-  mpz_clear(end);
-
-  mpz_t lenval;
-  mpz_init_set_ui(lenval, vals->size() + 1);
-  Expression* len = Expression::make_integer(&lenval, NULL, bloc);
-  mpz_clear(lenval);
-
+  vals->push_back(Expression::make_integer_ul(GC_END, uintptr_t, bloc));
+
+  Expression* len = Expression::make_integer_ul(vals->size() + 1, NULL,
+						bloc);
   Array_type* gc_symbol_type = Type::make_array_type(uintptr_t, len);
   return Expression::make_array_composite_literal(gc_symbol_type, vals, bloc);
 }
@@ -3267,10 +3254,8 @@ 
 {
   Location bloc = Linemap::predeclared_location();
   Type* uintptr_type = Type::lookup_integer_type("uintptr");
-  mpz_t opval;
-  mpz_init_set_ui(opval, GC_STRING);
-  (*vals)->push_back(Expression::make_integer(&opval, uintptr_type, bloc));
-  mpz_clear(opval);
+  (*vals)->push_back(Expression::make_integer_ul(GC_STRING, uintptr_type,
+						 bloc));
   (*vals)->push_back(*offset);
   this->advance_gc_offset(offset);
 }
@@ -3942,10 +3927,7 @@ 
 
   // We use GC_APTR here because we do not currently have a way to describe the
   // the type of the possible function closure.  FIXME.
-  mpz_t opval;
-  mpz_init_set_ui(opval, GC_APTR);
-  (*vals)->push_back(Expression::make_integer(&opval, uintptr_type, bloc));
-  mpz_clear(opval);
+  (*vals)->push_back(Expression::make_integer_ul(GC_APTR, uintptr_type, bloc));
   (*vals)->push_back(*offset);
   this->advance_gc_offset(offset);
 }
@@ -4361,10 +4343,8 @@ 
   Location loc = Linemap::predeclared_location();
   Type* uintptr_type = Type::lookup_integer_type("uintptr");
 
-  mpz_t opval;
-  mpz_init_set_ui(opval, this->to_type_->has_pointer() ? GC_PTR : GC_APTR);
-  (*vals)->push_back(Expression::make_integer(&opval, uintptr_type, loc));
-  mpz_clear(opval);
+  unsigned long opval = this->to_type_->has_pointer() ? GC_PTR : GC_APTR;
+  (*vals)->push_back(Expression::make_integer_ul(opval, uintptr_type, loc));
   (*vals)->push_back(*offset);
 
   if (this->to_type_->has_pointer())
@@ -5297,10 +5277,7 @@ 
   Type* uintptr_type = Type::lookup_integer_type("uintptr");
 
   // Get a 0.
-  mpz_t ival;
-  mpz_init_set_ui(ival, 0);
-  Expression* zero = Expression::make_integer(&ival, uintptr_type, bloc);
-  mpz_clear(ival);
+  Expression* zero = Expression::make_integer_ul(0, uintptr_type, bloc);
 
   // Make a temporary to hold the return value, initialized to 0.
   Temporary_statement* retval = Statement::make_temporary(uintptr_type, zero,
@@ -5329,11 +5306,8 @@ 
       else
 	{
 	  // Multiply retval by 33.
-	  mpz_init_set_ui(ival, 33);
-	  Expression* i33 = Expression::make_integer(&ival, uintptr_type,
-						     bloc);
-	  mpz_clear(ival);
-
+	  Expression* i33 = Expression::make_integer_ul(33, uintptr_type,
+							bloc);
 	  ref = Expression::make_temporary_reference(retval, bloc);
 	  Statement* s = Statement::make_assignment_operation(OPERATOR_MULTEQ,
 							      ref, i33, bloc);
@@ -5872,10 +5846,7 @@ 
   Type* uintptr_type = Type::lookup_integer_type("uintptr");
 
   // Get a 0.
-  mpz_t ival;
-  mpz_init_set_ui(ival, 0);
-  Expression* zero = Expression::make_integer(&ival, uintptr_type, bloc);
-  mpz_clear(ival);
+  Expression* zero = Expression::make_integer_ul(0, uintptr_type, bloc);
 
   // Make a temporary to hold the return value, initialized to 0.
   Temporary_statement* retval = Statement::make_temporary(uintptr_type, zero,
@@ -5909,9 +5880,7 @@ 
   gogo->start_block(bloc);
 
   // Multiply retval by 33.
-  mpz_init_set_ui(ival, 33);
-  Expression* i33 = Expression::make_integer(&ival, uintptr_type, bloc);
-  mpz_clear(ival);
+  Expression* i33 = Expression::make_integer_ul(33, uintptr_type, bloc);
 
   ref = Expression::make_temporary_reference(retval, bloc);
   Statement* s = Statement::make_assignment_operation(OPERATOR_MULTEQ, ref,
@@ -6431,10 +6400,8 @@ 
   size_t element_size = gogo->backend()->type_size(ebtype);
 
   Type* uintptr_type = Type::lookup_integer_type("uintptr");
-  mpz_t opval;
-  mpz_init_set_ui(opval, element_size == 0 ? GC_APTR : GC_SLICE);
-  (*vals)->push_back(Expression::make_integer(&opval, uintptr_type, bloc));
-  mpz_clear(opval);
+  unsigned long opval = element_size == 0 ? GC_APTR : GC_SLICE;
+  (*vals)->push_back(Expression::make_integer_ul(opval, uintptr_type, bloc));
   (*vals)->push_back(*offset);
 
   if (element_size != 0)
@@ -6472,12 +6439,10 @@ 
     {
       Type* uintptr_type = Type::lookup_integer_type("uintptr");
 
-      mpz_t op;
       if (stack_size < GC_STACK_CAPACITY)
   	{
-  	  mpz_init_set_ui(op, GC_ARRAY_START);
-  	  (*vals)->push_back(Expression::make_integer(&op, uintptr_type, bloc));
-  	  mpz_clear(op);
+	  (*vals)->push_back(Expression::make_integer_ul(GC_ARRAY_START,
+							 uintptr_type, bloc));
   	  (*vals)->push_back(*offset);
 	  Expression* uintptr_len =
 	    Expression::make_cast(uintptr_type, this->length_, bloc);
@@ -6488,20 +6453,17 @@ 
 				       Expression::TYPE_INFO_SIZE);
   	  (*vals)->push_back(width);
 
-  	  mpz_t zero;
-  	  mpz_init_set_ui(zero, 0UL);
-  	  Expression* offset2 =
-  	    Expression::make_integer(&zero, uintptr_type, bloc);
-  	  mpz_clear(zero);
+	  Expression* offset2 = Expression::make_integer_ul(0, uintptr_type,
+							    bloc);
 
 	  Type::gc_symbol(gogo, element_type, vals, &offset2, stack_size + 1);
-  	  mpz_init_set_ui(op, GC_ARRAY_NEXT);
-  	  (*vals)->push_back(Expression::make_integer(&op, uintptr_type, bloc));
+	  (*vals)->push_back(Expression::make_integer_ul(GC_ARRAY_NEXT,
+							 uintptr_type, bloc));
   	}
       else
   	{
-  	  mpz_init_set_ui(op, GC_REGION);
-  	  (*vals)->push_back(Expression::make_integer(&op, uintptr_type, bloc));
+	  (*vals)->push_back(Expression::make_integer_ul(GC_REGION,
+							 uintptr_type, bloc));
 	  (*vals)->push_back(*offset);
 
 	  Expression* width =
@@ -6509,7 +6471,6 @@ 
   	  (*vals)->push_back(width);
 	  (*vals)->push_back(Expression::make_gc_symbol(this));
   	}
-      mpz_clear(op);
       this->advance_gc_offset(offset);
     }
 }
@@ -6833,10 +6794,7 @@ 
   Location bloc = Linemap::predeclared_location();
   Type* uintptr_type = Type::lookup_integer_type("uintptr");
 
-  mpz_t opval;
-  mpz_init_set_ui(opval, GC_APTR);
-  (*vals)->push_back(Expression::make_integer(&opval, uintptr_type, bloc));
-  mpz_clear(opval);
+  (*vals)->push_back(Expression::make_integer_ul(GC_APTR, uintptr_type, bloc));
   (*vals)->push_back(*offset);
   this->advance_gc_offset(offset);
 }
@@ -6989,10 +6947,7 @@ 
     val |= 1;
   if (this->may_send_)
     val |= 2;
-  mpz_t iv;
-  mpz_init_set_ui(iv, val);
-  vals->push_back(Expression::make_integer(&iv, p->type(), bloc));
-  mpz_clear(iv);
+  vals->push_back(Expression::make_integer_ul(val, p->type(), bloc));
 
   ++p;
   go_assert(p == fields->end());
@@ -7023,10 +6978,8 @@ 
   Location bloc = Linemap::predeclared_location();
   Type* uintptr_type = Type::lookup_integer_type("uintptr");
 
-  mpz_t opval;
-  mpz_init_set_ui(opval, GC_CHAN_PTR);
-  (*vals)->push_back(Expression::make_integer(&opval, uintptr_type, bloc));
-  mpz_clear(opval);
+  (*vals)->push_back(Expression::make_integer_ul(GC_CHAN_PTR, uintptr_type,
+						 bloc));
   (*vals)->push_back(*offset);
  
   Type* unsafeptr_type = Type::make_pointer_type(Type::make_void_type());
@@ -7935,11 +7888,8 @@ 
   Location bloc = Linemap::predeclared_location();
   Type* uintptr_type = Type::lookup_integer_type("uintptr");
 
-  mpz_t opval;
-  mpz_init_set_ui(opval, this->is_empty() ? GC_EFACE : GC_IFACE);
-  (*vals)->push_back(Expression::make_integer(&opval, uintptr_type,
-					      bloc));
-  mpz_clear(opval);
+  unsigned long opval = this->is_empty() ? GC_EFACE : GC_IFACE;
+  (*vals)->push_back(Expression::make_integer_ul(opval, uintptr_type, bloc));
   (*vals)->push_back(*offset);
   this->advance_gc_offset(offset);
 }