diff mbox

Go patch committed: Verify types of sink variables

Message ID mcrr4ypxa1g.fsf@dhcp-172-18-216-180.mtv.corp.google.com
State New
Headers show

Commit Message

Ian Lance Taylor Jan. 24, 2012, 5:52 p.m. UTC
This patch makes gccgo verify the types of sink variables, so that we
issue an error as required for code like
	var _ map[[]int]bool
Bootstrapped and ran Go testsuite on x86_64-unknown-linux-gnu.
Committed to mainline.

Ian
diff mbox

Patch

diff -r 411e398e3e68 go/gogo.cc
--- a/go/gogo.cc	Tue Jan 24 09:20:57 2012 -0800
+++ b/go/gogo.cc	Tue Jan 24 09:40:18 2012 -0800
@@ -37,6 +37,7 @@ 
     imported_init_fns_(),
     unique_prefix_(),
     unique_prefix_specified_(false),
+    verify_types_(),
     interface_types_(),
     specific_type_functions_(),
     specific_type_functions_are_written_(false),
@@ -1282,6 +1283,15 @@ 
     }
 }
 
+// Add a type to verify.  This is used for types of sink variables, in
+// order to give appropriate error messages.
+
+void
+Gogo::add_type_to_verify(Type* type)
+{
+  this->verify_types_.push_back(type);
+}
+
 // Traversal class used to verify types.
 
 class Verify_types : public Traverse
@@ -1312,6 +1322,12 @@ 
 {
   Verify_types traverse;
   this->traverse(&traverse);
+
+  for (std::vector<Type*>::iterator p = this->verify_types_.begin();
+       p != this->verify_types_.end();
+       ++p)
+    (*p)->verify();
+  this->verify_types_.clear();
 }
 
 // Traversal class used to lower parse tree.
diff -r 411e398e3e68 go/gogo.h
--- a/go/gogo.h	Tue Jan 24 09:20:57 2012 -0800
+++ b/go/gogo.h	Tue Jan 24 09:40:18 2012 -0800
@@ -344,6 +344,11 @@ 
   Named_object*
   add_sink();
 
+  // Add a type which needs to be verified.  This is used for sink
+  // types, just to give appropriate error messages.
+  void
+  add_type_to_verify(Type* type);
+
   // Add a named object to the current namespace.  This is used for
   // import . "package".
   void
@@ -683,6 +688,8 @@ 
   std::string unique_prefix_;
   // Whether an explicit unique prefix was set by -fgo-prefix.
   bool unique_prefix_specified_;
+  // A list of types to verify.
+  std::vector<Type*> verify_types_;
   // A list of interface types defined while parsing.
   std::vector<Interface_type*> interface_types_;
   // Type specific functions to write out.
diff -r 411e398e3e68 go/parse.cc
--- a/go/parse.cc	Tue Jan 24 09:20:57 2012 -0800
+++ b/go/parse.cc	Tue Jan 24 09:40:18 2012 -0800
@@ -1911,6 +1911,8 @@ 
 	      return this->gogo_->add_variable(buf, var);
 	    }
 	}
+      if (type != NULL)
+	this->gogo_->add_type_to_verify(type);
       return this->gogo_->add_sink();
     }