Skip to content

Commit 5c49a77

Browse files
Chris Manghaneianlancetaylor
Chris Manghane
authored andcommitted
compiler: Create dummy labels for blank labels.
Fixes golang/go#11591. Change-Id: I777920fe3fbe18cd1223fa73f61903a099912aed Reviewed-on: https://go-review.googlesource.com/12043 Reviewed-by: Ian Lance Taylor <[email protected]>
1 parent 19ff97e commit 5c49a77

File tree

2 files changed

+25
-5
lines changed

2 files changed

+25
-5
lines changed

Diff for: go/gogo.cc

+21-5
Original file line numberDiff line numberDiff line change
@@ -1937,10 +1937,6 @@ Label*
19371937
Gogo::add_label_definition(const std::string& label_name,
19381938
Location location)
19391939
{
1940-
// A label with a blank identifier is never declared or defined.
1941-
if (label_name == "_")
1942-
return NULL;
1943-
19441940
go_assert(!this->functions_.empty());
19451941
Function* func = this->functions_.back().function->func_value();
19461942
Label* label = func->add_label_definition(this, label_name, location);
@@ -4724,7 +4720,13 @@ Function::add_label_definition(Gogo* gogo, const std::string& label_name,
47244720
std::pair<Labels::iterator, bool> ins =
47254721
this->labels_.insert(std::make_pair(label_name, lnull));
47264722
Label* label;
4727-
if (ins.second)
4723+
if (label_name == "_")
4724+
{
4725+
label = Label::create_dummy_label();
4726+
if (ins.second)
4727+
ins.first->second = label;
4728+
}
4729+
else if (ins.second)
47284730
{
47294731
// This is a new label.
47304732
label = new Label(label_name);
@@ -7625,6 +7627,20 @@ Label::get_addr(Translate_context* context, Location location)
76257627
return context->backend()->label_address(label, location);
76267628
}
76277629

7630+
// Return the dummy label that represents any instance of the blank label.
7631+
7632+
Label*
7633+
Label::create_dummy_label()
7634+
{
7635+
static Label* dummy_label;
7636+
if (dummy_label == NULL)
7637+
{
7638+
dummy_label = new Label("_");
7639+
dummy_label->set_is_used();
7640+
}
7641+
return dummy_label;
7642+
}
7643+
76287644
// Class Unnamed_label.
76297645

76307646
// Get the backend representation for an unnamed label.

Diff for: go/gogo.h

+4
Original file line numberDiff line numberDiff line change
@@ -2688,6 +2688,10 @@ class Label
26882688
Bexpression*
26892689
get_addr(Translate_context*, Location location);
26902690

2691+
// Return a dummy label, representing any instance of the blank label.
2692+
static Label*
2693+
create_dummy_label();
2694+
26912695
private:
26922696
// The name of the label.
26932697
std::string name_;

0 commit comments

Comments
 (0)