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/compile: comparison of pointers to zero sized values is inconsistent #52772

Closed
ngolin opened this issue May 8, 2022 · 1 comment
Closed

cmd/compile: comparison of pointers to zero sized values is inconsistent #52772

ngolin opened this issue May 8, 2022 · 1 comment

Comments

@ngolin
Copy link

@ngolin ngolin commented May 8, 2022

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

$ go version
go version go1.18.1 darwin/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
GO111MODULE="on"
GOARCH="amd64"
GOBIN=""
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOINSECURE=""
GOOS="darwin"
GOPROXY="https://goproxy.cn"
GOROOT="/usr/local/Cellar/go/1.18.1/libexec"
GOSUMDB="sum.golang.google.cn"
GOTMPDIR=""
GOTOOLDIR="/usr/local/Cellar/go/1.18.1/libexec/pkg/tool/darwin_amd64"
GOVCS=""
GOVERSION="go1.18.1"
GCCGO="gccgo"
GOAMD64="v1"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD="/dev/null"
GOWORK=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -arch x86_64 -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/2b/d9_jv6cs1bl2dqqblnzq4_8c0000gp/T/go-build2756878695=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

Given var s1 struct{} and var s2 struct{}, the result of &s1 == &s2 is inconsistent:
the following snippet yielding false:

package main

import (
	"fmt"
)

func main() {
	var s1 struct{}
	var s2 struct{}
	fmt.Println(&s1 == &s2) // false
}

while this snippet yielding true:

package main

import (
	"fmt"
	"unsafe"
)

func main() {
	var s1 struct{}
	var s2 struct{}
	fmt.Println(unsafe.Pointer(&s1), unsafe.Pointer(&s2))
	fmt.Println(&s1 == &s2) // true
}

What did you expect to see?

The results in two circumstances should be the same. Both of them should be true.

What did you see instead?

They are not. Quite confusing for newbies.

@ngolin ngolin changed the title cmd: comparison of pointers to zero sized values is inconsistent cmd/compile: comparison of pointers to zero sized values is inconsistent May 8, 2022
@D1CED
Copy link

@D1CED D1CED commented May 8, 2022

This issue is a duplicate of #47950. To recite the language specification:

Pointers to distinct zero-size variables may or may not be equal.

@cuonglm cuonglm closed this as completed May 8, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants