diff options
author | Ian Lance Taylor <ian@gcc.gnu.org> | 2015-07-31 17:52:38 +0000 |
---|---|---|
committer | Ian Lance Taylor <ian@gcc.gnu.org> | 2015-07-31 17:52:38 +0000 |
commit | 2e2fc3bd51b507987542acb13e6aa42cf3a94f68 (patch) | |
tree | 0ae30aae68ac2ad7743476883cba3bddde373e20 /gcc | |
parent | d459fde28f3d37e03d87b221b504a525ddb58665 (diff) | |
download | gcc-2e2fc3bd51b507987542acb13e6aa42cf3a94f68.zip gcc-2e2fc3bd51b507987542acb13e6aa42cf3a94f68.tar.gz gcc-2e2fc3bd51b507987542acb13e6aa42cf3a94f68.tar.bz2 |
compiler: Don't allow builtin function values.
According to the spec, http://golang.org/ref/spec#Built-in_functions:
"built-in functions do not have standard Go types, so they can only
appear in call expressions; they cannot be used as function values."
Fixes golang/go#11570.
Reviewed-on: https://go-review.googlesource.com/12543
From-SVN: r226448
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/go/gofrontend/MERGE | 2 | ||||
-rw-r--r-- | gcc/go/gofrontend/gogo.cc | 22 |
2 files changed, 23 insertions, 1 deletions
diff --git a/gcc/go/gofrontend/MERGE b/gcc/go/gofrontend/MERGE index 0915152..caf0af5 100644 --- a/gcc/go/gofrontend/MERGE +++ b/gcc/go/gofrontend/MERGE @@ -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. diff --git a/gcc/go/gofrontend/gogo.cc b/gcc/go/gofrontend/gogo.cc index d521fb1..0824102 100644 --- a/gcc/go/gofrontend/gogo.cc +++ b/gcc/go/gofrontend/gogo.cc @@ -3154,6 +3154,28 @@ Check_types_traverse::variable(Named_object* named_object) 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() |