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

runtime/cgo: cannot build with -Wsign-compare #44340

Closed
elagergren-spideroak opened this issue Feb 17, 2021 · 5 comments
Closed

runtime/cgo: cannot build with -Wsign-compare #44340

elagergren-spideroak opened this issue Feb 17, 2021 · 5 comments
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done.
Milestone

Comments

@elagergren-spideroak
Copy link

elagergren-spideroak commented Feb 17, 2021

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

$ go version
go version go1.16 linux/amd64
$ gcc version
gcc (Debian 8.3.0-6) 8.3.0

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
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/root/.cache/go-build"
GOENV="/root/.config/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
GOVCS=""
GOVERSION="go1.16"
GCCGO="gccgo"
AR="llvm-ar-11"
CC="clang-11"
CXX="clang++-11"
CGO_ENABLED="1"
GOMOD="/dev/null"
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 -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build291458045=/tmp/go-build -gno-record-gcc-switches"

What did you do?

$ cat x.go
package main

/*
#include <stdio.h>
static inline void hello() {
	puts("hello, world!");
}
*/
import "C"

func main() {
	C.hello()
}
$ CGO_CFLAGS="$(go env CGO_CFLAGS) -Wsign-compare" go build x.go

What did you expect to see?

Successful compilation.

What did you see instead?

# runtime/cgo
linux_syscall.c:42:2: error: comparison of integers of different signs: 'uintptr_t' (aka 'unsigned long') and 'int' [-Werror,-Wsign-compare]
linux_syscall.c:35:11: note: expanded from macro 'SET_RETVAL'
linux_syscall.c:47:2: error: comparison of integers of different signs: 'uintptr_t' (aka 'unsigned long') and 'int' [-Werror,-Wsign-compare]
linux_syscall.c:35:11: note: expanded from macro 'SET_RETVAL'
linux_syscall.c:52:2: error: comparison of integers of different signs: 'uintptr_t' (aka 'unsigned long') and 'int' [-Werror,-Wsign-compare]
linux_syscall.c:35:11: note: expanded from macro 'SET_RETVAL'
linux_syscall.c:57:2: error: comparison of integers of different signs: 'uintptr_t' (aka 'unsigned long') and 'int' [-Werror,-Wsign-compare]
linux_syscall.c:35:11: note: expanded from macro 'SET_RETVAL'
linux_syscall.c:62:2: error: comparison of integers of different signs: 'uintptr_t' (aka 'unsigned long') and 'int' [-Werror,-Wsign-compare]
linux_syscall.c:35:11: note: expanded from macro 'SET_RETVAL'
linux_syscall.c:67:2: error: comparison of integers of different signs: 'uintptr_t' (aka 'unsigned long') and 'int' [-Werror,-Wsign-compare]
linux_syscall.c:35:11: note: expanded from macro 'SET_RETVAL'
linux_syscall.c:73:2: error: comparison of integers of different signs: 'uintptr_t' (aka 'unsigned long') and 'int' [-Werror,-Wsign-compare]
linux_syscall.c:35:11: note: expanded from macro 'SET_RETVAL'
linux_syscall.c:79:2: error: comparison of integers of different signs: 'uintptr_t' (aka 'unsigned long') and 'int' [-Werror,-Wsign-compare]
linux_syscall.c:35:11: note: expanded from macro 'SET_RETVAL'
linux_syscall.c:84:2: error: comparison of integers of different signs: 'uintptr_t' (aka 'unsigned long') and 'int' [-Werror,-Wsign-compare]
linux_syscall.c:35:11: note: expanded from macro 'SET_RETVAL'
@seankhliao seankhliao added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Feb 17, 2021
@gopherbot
Copy link

Change https://golang.org/cl/293209 mentions this issue: runtime/cgo: add cast in C code to avoid C compiler warning

@ianlancetaylor
Copy link
Contributor

@gopherbot Please open backport to 1.16.

This problem makes it hard to build 1.16 programs that use cgo if you want to use -Wsign-compare in CGO_CFLAGS (to check your own C code). The CL fixes the problem.

@gopherbot
Copy link

Backport issue(s) opened: #44346 (for 1.16).

Remember to create the cherry-pick CL(s) as soon as the patch is submitted to master, according to https://golang.org/wiki/MinorReleases.

@elagergren-spideroak
Copy link
Author

@ianlancetaylor thanks.

@gopherbot
Copy link

Change https://golang.org/cl/293411 mentions this issue: [release-branch.go1.16] runtime/cgo: add cast in C code to avoid C compiler warning

gopherbot pushed a commit that referenced this issue Feb 18, 2021
…mpiler warning

For #44340
Fixes #44346

Change-Id: Id80dd1f44a988b653933732afcc8e49a826affc4
Reviewed-on: https://go-review.googlesource.com/c/go/+/293209
Reviewed-by: Andrew G. Morgan <agm@google.com>
Reviewed-by: Bryan C. Mills <bcmills@google.com>
Trust: Ian Lance Taylor <iant@golang.org>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
(cherry picked from commit 07ef313)
Reviewed-on: https://go-review.googlesource.com/c/go/+/293411
TryBot-Result: Go Bot <gobot@golang.org>
@toothrot toothrot added this to the Go1.17 milestone Feb 18, 2021
@dmitshur dmitshur added NeedsFix The path to resolution is known, but the work has not been done. and removed NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. labels Feb 18, 2021
@golang golang locked and limited conversation to collaborators Feb 18, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done.
Projects
None yet
Development

No branches or pull requests

6 participants