Skip to content

Commit 8416894

Browse files
author
ian
committed
compiler: Don't record dependencies of invalid redefinitions.
The gofrontend would crash when trying to find the initialization order of a variable list where one of the listed variables was an invalid redefinition of another in a call statement. This patch fixes initialization from call statements to consider invalid redefinitions before recording dependency information. Fixes golang/go#11543. Reviewed-on: https://go-review.googlesource.com/13895 git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@227276 138bc75d-0d04-0410-961f-82ee72b054a4
1 parent a5bc39b commit 8416894

File tree

4 files changed

+26
-2
lines changed

4 files changed

+26
-2
lines changed

gcc/go/gofrontend/MERGE

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
5ee78e7d52a4cad0b23f5bc62e5b452489243c70
1+
a1d2cac484f46068b5a6ddf3e041d425a3d25e0c
22

33
The first line of this file holds the git revision number of the last
44
merge done from the gofrontend repository.

gcc/go/gofrontend/gogo.cc

+4-1
Original file line numberDiff line numberDiff line change
@@ -6753,7 +6753,8 @@ Unknown_name::set_real_named_object(Named_object* no)
67536753
Named_object::Named_object(const std::string& name,
67546754
const Package* package,
67556755
Classification classification)
6756-
: name_(name), package_(package), classification_(classification)
6756+
: name_(name), package_(package), classification_(classification),
6757+
is_redefinition_(false)
67576758
{
67586759
if (Gogo::is_sink_name(name))
67596760
go_assert(classification == NAMED_OBJECT_SINK);
@@ -7439,6 +7440,8 @@ Bindings::new_definition(Named_object* old_object, Named_object* new_object)
74397440
else
74407441
error_at(new_object->location(), "redefinition of %qs: %s", n.c_str(),
74417442
reason.c_str());
7443+
old_object->set_is_redefinition();
7444+
new_object->set_is_redefinition();
74427445

74437446
inform(old_object->location(), "previous definition of %qs was here",
74447447
n.c_str());

gcc/go/gofrontend/gogo.h

+13
Original file line numberDiff line numberDiff line change
@@ -2389,6 +2389,17 @@ class Named_object
23892389
void
23902390
export_named_object(Export*) const;
23912391

2392+
// Mark this named object as an invalid redefinition of another object.
2393+
void
2394+
set_is_redefinition()
2395+
{ this->is_redefinition_ = true; }
2396+
2397+
// Return whether or not this object is a invalid redefinition of another
2398+
// object.
2399+
bool
2400+
is_redefinition() const
2401+
{ return this->is_redefinition_; }
2402+
23922403
private:
23932404
Named_object(const std::string&, const Package*, Classification);
23942405

@@ -2412,6 +2423,8 @@ class Named_object
24122423
Function_declaration* func_declaration_value;
24132424
Package* package_value;
24142425
} u_;
2426+
// True if this object is an invalid redefinition of another object.
2427+
bool is_redefinition_;
24152428
};
24162429

24172430
// A binding contour. This binds names to objects.

gcc/go/gofrontend/parse.cc

+8
Original file line numberDiff line numberDiff line change
@@ -1741,6 +1741,14 @@ Parse::init_vars_from_call(const Typed_identifier_list* vars, Type* type,
17411741
first_var = no;
17421742
else
17431743
{
1744+
// If the current object is a redefinition of another object, we
1745+
// might have already recorded the dependency relationship between
1746+
// it and the first variable. Either way, an error will be
1747+
// reported for the redefinition and we don't need to properly
1748+
// record dependency information for an invalid program.
1749+
if (no->is_redefinition())
1750+
continue;
1751+
17441752
// The subsequent vars have an implicit dependency on
17451753
// the first one, so that everything gets initialized in
17461754
// the right order and so that we detect cycles

0 commit comments

Comments
 (0)