cmd/cgo: reject references to builtin functions other than calls

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>
This commit is contained in:
Alexander Menzhinsky 2017-04-17 16:13:59 -05:00 committed by Ian Lance Taylor
parent 743fe0697d
commit 2463a49ebb
3 changed files with 12 additions and 0 deletions

View 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