public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* Go patch committed: Don't allow builtin function values that are not called
@ 2015-07-31 18:28 Ian Lance Taylor
  0 siblings, 0 replies; only message in thread
From: Ian Lance Taylor @ 2015-07-31 18:28 UTC (permalink / raw)
  To: gcc-patches, gofrontend-dev

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

The Go spec says that builtin functions may not be referenced other
than being called.  This patch from Chris Manghane implements that
restriction in the Go frontend.  This fixes
https://golang.org/issue/11570 .  Bootstrapped and ran Go testsuite on
x86_64-unknown-linux-gnu.  Committed to mainline.

Ian

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

Index: gcc/go/gofrontend/MERGE
===================================================================
--- gcc/go/gofrontend/MERGE	(revision 226366)
+++ gcc/go/gofrontend/MERGE	(working copy)
@@ -1,4 +1,4 @@
-9931f2c150e2da4b7d468db332823d8ef4fb8c34
+4c676d965c19b9c5d5e5049d0f8070502e9c27b0
 
 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 226009)
+++ gcc/go/gofrontend/gogo.cc	(working copy)
@@ -3154,6 +3154,28 @@ Check_types_traverse::variable(Named_obj
 		     reason.c_str());
 	  var->clear_init();
 	}
+      else if (init != NULL
+               && init->func_expression() != NULL)
+        {
+          Named_object* no = init->func_expression()->named_object();
+          Function_type* fntype;
+          if (no->is_function())
+            fntype = no->func_value()->type();
+          else if (no->is_function_declaration())
+            fntype = no->func_declaration_value()->type();
+          else
+            go_unreachable();
+
+          // Builtin functions cannot be used as function values for variable
+          // initialization.
+          if (fntype->is_builtin())
+            {
+              error_at(init->location(),
+                       "invalid use of special builtin function %qs; "
+                       "must be called",
+                       no->message_name().c_str());
+            }
+        }
       else if (!var->is_used()
 	       && !var->is_global()
 	       && !var->is_parameter()

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

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

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-07-31 18:28 Go patch committed: Don't allow builtin function values that are not called 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).