]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/cgo: reject references to builtin functions other than calls
authorAlexander Menzhinsky <amenzhinsky@gmail.com>
Mon, 17 Apr 2017 21:13:59 +0000 (16:13 -0500)
committerIan Lance Taylor <iant@golang.org>
Tue, 18 Apr 2017 22:14:43 +0000 (22:14 +0000)
Here we restrict using cgo builtin references because internally they're go functions
as opposed to C usafe.Pointer values.

Fixes #18889

Change-Id: I1e4332e4884063ccbaf9772c172d4462ec8f3d13
Reviewed-on: https://go-review.googlesource.com/40934
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>

misc/cgo/errors/issue18889.go [new file with mode: 0644]
misc/cgo/errors/test.bash
src/cmd/cgo/gcc.go

diff --git a/misc/cgo/errors/issue18889.go b/misc/cgo/errors/issue18889.go
new file mode 100644 (file)
index 0000000..bba6b8f
--- /dev/null
@@ -0,0 +1,7 @@
+package main
+
+import "C"
+
+func main() {
+       _ = C.malloc // ERROR HERE
+}
index 27d7dc1cfeef1120969e715d6732891a35c61641..e9e36ce2cf09efd160641f324cc0d3b003a4d4ff 100755 (executable)
@@ -47,6 +47,7 @@ expect issue13635.go C.uchar C.schar C.ushort C.uint C.ulong C.longlong C.ulongl
 check issue13830.go
 check issue16116.go
 check issue16591.go
+check issue18889.go
 
 if ! go build issue14669.go; then
        exit 1
index 8be5f25e6d599df071606a0727ab671a8b7e990c..3b6d4580de3eabcdc3f864cb0969b6d761b6c4c5 100644 (file)
@@ -1086,6 +1086,10 @@ func (p *Package) rewriteRef(f *File) {
                        }
                case "expr":
                        if r.Name.Kind == "func" {
+                               if builtinDefs[r.Name.C] != "" {
+                                       error_(r.Pos(), "use of builtin '%s' not in function call", fixGo(r.Name.C))
+                               }
+
                                // Function is being used in an expression, to e.g. pass around a C function pointer.
                                // Create a new Name for this Ref which causes the variable to be declared in Go land.
                                fpName := "fp_" + r.Name.Go