|| (no->is_const() && no->const_value()->is_sink()))
continue;
+ // Skip global sink variables with static initializers. With
+ // non-static initializers we have to evaluate for side effects,
+ // and we wind up initializing a dummy variable. That is not
+ // ideal but it works and it's a rare case.
+ if (no->is_variable()
+ && no->var_value()->is_global_sink()
+ && !no->var_value()->has_pre_init()
+ && (no->var_value()->init() == NULL
+ || no->var_value()->init()->is_static_initializer()))
+ continue;
+
// There is nothing useful we can output for constants which
// have ideal or non-integral type.
if (no->is_const())
: type_(type), init_(init), preinit_(NULL), location_(location),
backend_(NULL), is_global_(is_global), is_parameter_(is_parameter),
is_closure_(false), is_receiver_(is_receiver),
- is_varargs_parameter_(false), is_used_(false),
+ is_varargs_parameter_(false), is_global_sink_(false), is_used_(false),
is_address_taken_(false), is_non_escaping_address_taken_(false),
seen_(false), init_is_lowered_(false), init_is_flattened_(false),
type_from_init_tuple_(false), type_from_range_index_(false),
is_varargs_parameter() const
{ return this->is_varargs_parameter_; }
+ // Return whether this is a global sink variable, created only to
+ // run an initializer.
+ bool
+ is_global_sink() const
+ { return this->is_global_sink_; }
+
+ // Record that this is a global sink variable.
+ void
+ set_is_global_sink()
+ {
+ go_assert(this->is_global_);
+ this->is_global_sink_ = true;
+ }
+
// Whether this variable's address is taken.
bool
is_address_taken() const
bool is_receiver_ : 1;
// Whether this is the varargs parameter of a function.
bool is_varargs_parameter_ : 1;
+ // Whether this is a global sink variable created to run an
+ // initializer.
+ bool is_global_sink_ : 1;
// Whether this variable is ever referenced.
bool is_used_ : 1;
// Whether something takes the address of this variable. For a
if (type == NULL && init == NULL)
type = Type::lookup_bool_type();
Variable* var = new Variable(type, init, true, false, false, location);
+ var->set_is_global_sink();
static int count;
char buf[30];
snprintf(buf, sizeof buf, "_.%d", count);