Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmd/cgo: warning: built-in function ‘free’ declared as non-function #32411

Open
yath opened this issue Jun 3, 2019 · 3 comments

Comments

Projects
None yet
3 participants
@yath
Copy link

commented Jun 3, 2019

What version of Go are you using (go version)?

$ go version
go version go1.11.6 linux/amd64

Does this issue reproduce with the latest release?

Yes.

What operating system and processor architecture are you using (go env)?

go env Output
$ go env
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/yath/.cache/go-build"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/yath/go"
GOPROXY="https://proxy.golang.org,direct"
GORACE=""
GOROOT="/tmp/go"
GOTMPDIR=""
GOTOOLDIR="/tmp/go/pkg/tool/linux_amd64"
GCCGO="/usr/bin/gccgo"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build688375222=/tmp/go-build -gno-record-gcc-switches"
GOROOT/bin/go version: go version devel +98100c56da Mon Jun 3 01:37:58 2019 +0000 linux/amd64
GOROOT/bin/go tool compile -V: compile version devel +98100c56da Mon Jun 3 01:37:58 2019 +0000
uname -sr: Linux 5.1.5
Distributor ID:	Debian
Description:	Debian GNU/Linux 10 (buster)
Release:	10
Codename:	buster
/lib/x86_64-linux-gnu/libc.so.6: GNU C Library (Debian GLIBC 2.28-10) stable release version 2.28.
lldb --version: lldb version 6.0.1
gdb --version: GNU gdb (Debian 8.2.1-2) 8.2.1

What did you do?

go run the following program that is using C.free as a value. (In actual code, it’s passed to a foo_set_free_fun(void (*)(void *)).) The warning is not emit when calling C.free(), nor is it when e.g. printing the address of C.getenv.

package main

// #include <stdlib.h>
import "C"
import "fmt"

func main() {
        fmt.Printf("%#v\n", C.free)
}

What did you expect to see?

(unsafe.Pointer)(0x402030)

What did you see instead?

# command-line-arguments
cgo-generated-wrappers:1:13: warning: built-in function ‘free’ declared as non-function [-Wbuiltin-declaration-mismatch]
(unsafe.Pointer)(0x402030)
@ianlancetaylor

This comment has been minimized.

Copy link
Contributor

commented Jun 3, 2019

Does the code work other than producing a warning?

@ianlancetaylor ianlancetaylor added this to the Go1.14 milestone Jun 3, 2019

@yath

This comment has been minimized.

Copy link
Author

commented Jun 3, 2019

It’s actually a bit hard to trace in the real code, but the following code:

package main

// #include <stdlib.h>
// void __attribute__((noinline)) call_free(void (*f)(void *), char *p) { f(p); }
import "C"
import "fmt"

func main() {
        p := C.CString("test")
        fmt.Printf("p: %#v\n", p)
        C.call_free((*[0]byte)(C.free), p)
}

appears to work as expected:

% ltrace -e free ./main 2>&1|grep -A1 p:      
p: (*main._Ctype_char)(0xef4930)
main->free(0xef4930)                             = <void>
%
@gertcuykens

This comment has been minimized.

Copy link

commented Jun 4, 2019

I can reproduce this doing

gert@debian:~/go/src/crawshaw.io/sqlite:master$ go test -v
# crawshaw.io/sqlite
cgo-generated-wrappers:7:13: warning: built-in function ‘free’ declared as non-function
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.