public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* Go patch committed: Check types in function declarations
@ 2015-07-31 23:17 Ian Lance Taylor
  0 siblings, 0 replies; only message in thread
From: Ian Lance Taylor @ 2015-07-31 23:17 UTC (permalink / raw)
  To: gcc-patches, gofrontend-dev

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

This patch to the Go frontend by Chris Manghane checks that the types
that appear in function declarations are valid.  This fixes
https://golang.org/issue/11567.  Bootstrapped and ran Go testsuite on
x86_64-unknown-linux-gnu.  Committed to mainline.

Ian

[-- Attachment #2: foo.txt --]
[-- Type: text/plain, Size: 2488 bytes --]

Index: gcc/go/gofrontend/MERGE
===================================================================
--- gcc/go/gofrontend/MERGE	(revision 226452)
+++ gcc/go/gofrontend/MERGE	(working copy)
@@ -1,4 +1,4 @@
-19f0ec56bf278a9cbb100c6b24ec1a12c95ec41a
+bc4dda16f8686ab6e7335adfdfd2c6cc81cb2eb5
 
 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 226448)
+++ gcc/go/gofrontend/gogo.cc	(working copy)
@@ -3258,6 +3258,17 @@ Gogo::check_types()
 {
   Check_types_traverse traverse(this);
   this->traverse(&traverse);
+
+  Bindings* bindings = this->current_bindings();
+  for (Bindings::const_declarations_iterator p = bindings->begin_declarations();
+       p != bindings->end_declarations();
+       ++p)
+    {
+      // Also check the types in a function declaration's signature.
+      Named_object* no = p->second;
+      if (no->is_function_declaration())
+        no->func_declaration_value()->check_types();
+    }
 }
 
 // Check the types in a single block.
@@ -5297,6 +5308,26 @@ Function_declaration::build_backend_desc
     }
 }
 
+// Check that the types used in this declaration's signature are defined.
+// Reports errors for any undefined type.
+
+void
+Function_declaration::check_types() const
+{
+  // Calling Type::base will give errors for any undefined types.
+  Function_type* fntype = this->type();
+  if (fntype->receiver() != NULL)
+    fntype->receiver()->type()->base();
+  if (fntype->parameters() != NULL)
+    {
+      const Typed_identifier_list* params = fntype->parameters();
+      for (Typed_identifier_list::const_iterator p = params->begin();
+           p != params->end();
+           ++p)
+        p->type()->base();
+    }
+}
+
 // Return the function's decl after it has been built.
 
 Bfunction*
Index: gcc/go/gofrontend/gogo.h
===================================================================
--- gcc/go/gofrontend/gogo.h	(revision 226009)
+++ gcc/go/gofrontend/gogo.h	(working copy)
@@ -1394,6 +1394,10 @@ class Function_declaration
   export_func(Export* exp, const std::string& name) const
   { Function::export_func_with_type(exp, name, this->fntype_); }
 
+  // Check that the types used in this declaration's signature are defined.
+  void
+  check_types() const;
+
  private:
   // The type of the function.
   Function_type* fntype_;

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

only message in thread, other threads:[~2015-07-31 22:16 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-07-31 23:17 Go patch committed: Check types in function declarations 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).