Skip to content

cmd/compile: fatal error: checkptr: pointer arithmetic computed bad pointer value #64467

@gucio321

Description

@gucio321

Go version

go version go1.21.3 linux/amd64

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

GO111MODULE=''
GOARCH='amd64'
GOBIN=''
GOCACHE='/home/username/.cache/go-build'
GOENV='/home/username/.config/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFLAGS=''
GOHOSTARCH='amd64'
GOHOSTOS='linux'
GOINSECURE=''
GOMODCACHE='/home/username/go/pkg/mod'
GONOPROXY=''
GONOSUMDB=''
GOOS='linux'
GOPATH='/home/username/go'
GOPRIVATE=''
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/usr/local/go'
GOSUMDB='sum.golang.org'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/usr/local/go/pkg/tool/linux_amd64'
GOVCS=''
GOVERSION='go1.21.3'
GCCGO='gccgo'
GOAMD64='v1'
AR='ar'
CC='gcc'
CXX='g++'
CGO_ENABLED='1'
GOMOD='/dev/null'
GOWORK=''
CGO_CFLAGS='-O2 -g'
CGO_CPPFLAGS=''
CGO_CXXFLAGS='-O2 -g'
CGO_FFLAGS='-O2 -g'
CGO_LDFLAGS='-O2 -g'
PKG_CONFIG='pkg-config'
GOGCCFLAGS='-fPIC -m64 -pthread -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=/tmp/go-build2422207597=/tmp/go-build -gno-record-gcc-switches'

What did you do?

I want to cast an unintptr to unsafe.Pointer.
When running with -race it crashes:

fatal error: checkptr: pointer arithmetic computed bad pointer value

Here is the code

func (selfStruct *TextureID) c() (result C.ImTextureID, fin func(
        self := selfStruct.Data

        return (C.ImTextureID)(unsafe.Pointer(self)), func() {} // <- this line causes crash
}

What did you expect to see?

No panic when running with -race

In reference to #64111 as a solution of that issue I was suggested to use uintptr as an alternative to unsafe.pointer.
However I need to cast it (for a while) to unsafe.pointer to be able to pass it to C function taking void*

What did you see instead?

fatal error: checkptr: pointer arithmetic computed bad pointer value

Metadata

Metadata

Assignees

No one assigned

    Labels

    NeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.compiler/runtimeIssues related to the Go compiler and/or runtime.

    Type

    No type

    Projects

    Status

    In Progress

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions