Skip to content

Commit

Permalink
compiler: Create dummy labels for blank labels.
Browse files Browse the repository at this point in the history
Fixes golang/go#11591.

Change-Id: I777920fe3fbe18cd1223fa73f61903a099912aed
Reviewed-on: https://go-review.googlesource.com/12043
Reviewed-by: Ian Lance Taylor <iant@golang.org>
  • Loading branch information
Chris Manghane authored and ianlancetaylor committed Jul 20, 2015
1 parent 19ff97e commit 5c49a77
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 5 deletions.
26 changes: 21 additions & 5 deletions go/gogo.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1937,10 +1937,6 @@ Label*
Gogo::add_label_definition(const std::string& label_name,
Location location)
{
// A label with a blank identifier is never declared or defined.
if (label_name == "_")
return NULL;

go_assert(!this->functions_.empty());
Function* func = this->functions_.back().function->func_value();
Label* label = func->add_label_definition(this, label_name, location);
Expand Down Expand Up @@ -4724,7 +4720,13 @@ Function::add_label_definition(Gogo* gogo, const std::string& label_name,
std::pair<Labels::iterator, bool> ins =
this->labels_.insert(std::make_pair(label_name, lnull));
Label* label;
if (ins.second)
if (label_name == "_")
{
label = Label::create_dummy_label();
if (ins.second)
ins.first->second = label;
}
else if (ins.second)
{
// This is a new label.
label = new Label(label_name);
Expand Down Expand Up @@ -7625,6 +7627,20 @@ Label::get_addr(Translate_context* context, Location location)
return context->backend()->label_address(label, location);
}

// Return the dummy label that represents any instance of the blank label.

Label*
Label::create_dummy_label()
{
static Label* dummy_label;
if (dummy_label == NULL)
{
dummy_label = new Label("_");
dummy_label->set_is_used();
}
return dummy_label;
}

// Class Unnamed_label.

// Get the backend representation for an unnamed label.
Expand Down
4 changes: 4 additions & 0 deletions go/gogo.h
Original file line number Diff line number Diff line change
Expand Up @@ -2688,6 +2688,10 @@ class Label
Bexpression*
get_addr(Translate_context*, Location location);

// Return a dummy label, representing any instance of the blank label.
static Label*
create_dummy_label();

private:
// The name of the label.
std::string name_;
Expand Down

0 comments on commit 5c49a77

Please sign in to comment.