This patch by Chris Manghane fixes a Go frontend crash on invalid code that redefines a variable. This fixes https://golang.org/issue/11543 . Bootstrapped and ran Go testsuite on x86_64-unknown-linux-gnu. Committed to mainline.
Ian
Index: gcc/go/gofrontend/MERGE =================================================================== --- gcc/go/gofrontend/MERGE (revision 227245) +++ gcc/go/gofrontend/MERGE (working copy) @@ -1,4 +1,4 @@ -5ee78e7d52a4cad0b23f5bc62e5b452489243c70 +a1d2cac484f46068b5a6ddf3e041d425a3d25e0c The first line of this file holds the git revision number of the last merge done from the gofrontend repository. Index: gcc/go/gofrontend/gogo.cc =================================================================== --- gcc/go/gofrontend/gogo.cc (revision 226899) +++ gcc/go/gofrontend/gogo.cc (working copy) @@ -6753,7 +6753,8 @@ Unknown_name::set_real_named_object(Name Named_object::Named_object(const std::string& name, const Package* package, Classification classification) - : name_(name), package_(package), classification_(classification) + : name_(name), package_(package), classification_(classification), + is_redefinition_(false) { if (Gogo::is_sink_name(name)) go_assert(classification == NAMED_OBJECT_SINK); @@ -7439,6 +7440,8 @@ Bindings::new_definition(Named_object* o else error_at(new_object->location(), "redefinition of %qs: %s", n.c_str(), reason.c_str()); + old_object->set_is_redefinition(); + new_object->set_is_redefinition(); inform(old_object->location(), "previous definition of %qs was here", n.c_str()); Index: gcc/go/gofrontend/gogo.h =================================================================== --- gcc/go/gofrontend/gogo.h (revision 226846) +++ gcc/go/gofrontend/gogo.h (working copy) @@ -2389,6 +2389,17 @@ class Named_object void export_named_object(Export*) const; + // Mark this named object as an invalid redefinition of another object. + void + set_is_redefinition() + { this->is_redefinition_ = true; } + + // Return whether or not this object is a invalid redefinition of another + // object. + bool + is_redefinition() const + { return this->is_redefinition_; } + private: Named_object(const std::string&, const Package*, Classification); @@ -2412,6 +2423,8 @@ class Named_object Function_declaration* func_declaration_value; Package* package_value; } u_; + // True if this object is an invalid redefinition of another object. + bool is_redefinition_; }; // A binding contour. This binds names to objects. Index: gcc/go/gofrontend/parse.cc =================================================================== --- gcc/go/gofrontend/parse.cc (revision 227160) +++ gcc/go/gofrontend/parse.cc (working copy) @@ -1741,6 +1741,14 @@ Parse::init_vars_from_call(const Typed_i first_var = no; else { + // If the current object is a redefinition of another object, we + // might have already recorded the dependency relationship between + // it and the first variable. Either way, an error will be + // reported for the redefinition and we don't need to properly + // record dependency information for an invalid program. + if (no->is_redefinition()) + continue; + // The subsequent vars have an implicit dependency on // the first one, so that everything gets initialized in // the right order and so that we detect cycles