public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* Go patch committed: Don't crash when declaring method on unknown name
@ 2010-12-21 22:19 Ian Lance Taylor
  0 siblings, 0 replies; only message in thread
From: Ian Lance Taylor @ 2010-12-21 22:19 UTC (permalink / raw)
  To: gcc-patches, gofrontend-dev

[-- Attachment #1: Type: text/plain, Size: 251 bytes --]

This patch to the Go frontend avoids a compiler crash when declaring a
method on an unknown name.  This may be valid if the name is later
defined as a type.  Bootstrapped and ran Go testsuite on
x86_64-unknown-linux-gnu.  Committed to mainline.

Ian


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: declare_as_type --]
[-- Type: text/x-diff, Size: 1672 bytes --]

diff -r 784214e96a81 go/gogo.cc
--- a/go/gogo.cc	Tue Dec 21 10:58:41 2010 -0800
+++ b/go/gogo.cc	Tue Dec 21 11:53:06 2010 -0800
@@ -3710,6 +3710,18 @@
   this->u_.func_value = function;
 }
 
+// Declare an unknown object as a type declaration.
+
+void
+Named_object::declare_as_type()
+{
+  gcc_assert(this->classification_ == NAMED_OBJECT_UNKNOWN);
+  Unknown_name* unk = this->u_.unknown_value;
+  this->classification_ = NAMED_OBJECT_TYPE_DECLARATION;
+  this->u_.type_declaration = new Type_declaration(unk->location());
+  delete unk;
+}
+
 // Return the location of a named object.
 
 source_location
diff -r 784214e96a81 go/gogo.h
--- a/go/gogo.h	Tue Dec 21 10:58:41 2010 -0800
+++ b/go/gogo.h	Tue Dec 21 11:53:06 2010 -0800
@@ -1815,6 +1815,10 @@
   void
   set_function_value(Function*);
 
+  // Declare an unknown name as a type declaration.
+  void
+  declare_as_type();
+
   // Export this object.
   void
   export_named_object(Export*) const;
diff -r 784214e96a81 go/types.cc
--- a/go/types.cc	Tue Dec 21 10:58:41 2010 -0800
+++ b/go/types.cc	Tue Dec 21 11:53:06 2010 -0800
@@ -8013,7 +8013,8 @@
 				     Function* function)
 {
   Named_object* no = this->named_object();
-  gcc_assert(no->is_type_declaration());
+  if (no->is_unknown())
+    no->declare_as_type();
   return no->type_declaration_value()->add_method(name, function);
 }
 
@@ -8026,7 +8027,8 @@
 						 source_location location)
 {
   Named_object* no = this->named_object();
-  gcc_assert(no->is_type_declaration());
+  if (no->is_unknown())
+    no->declare_as_type();
   Type_declaration* td = no->type_declaration_value();
   return td->add_method_declaration(name, type, location);
 }

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2010-12-21 20:32 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-12-21 22:19 Go patch committed: Don't crash when declaring method on unknown name Ian Lance Taylor

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).