Skip to content

cmd/compile: ICE disjointTypes on copy from unsafe.Slice(uintptr) into [N]byte (go1.26.2 amd64) #81532

Closed

Description

@azusayn

Go version

go version go1.26.2 windows/amd64

Output of go env in your module/workspace:

GOARCH=amd64
GOOS=windows
GOAMD64=v1
GOVERSION=go1.26.2
GOROOT=C:\Program Files\Go

(Full go env available on request.)

What did you do?

go build of:

package main

import "unsafe"

func cPtr(p uintptr) unsafe.Pointer {
	return *(*unsafe.Pointer)(unsafe.Pointer(&p))
}

func f(p uintptr) [32]byte {
	var a [32]byte
	copy(a[:], unsafe.Slice((*byte)(cPtr(p)), 32))
	return a
}

func main() {
	var buf [32]byte
	_ = f(uintptr(unsafe.Pointer(&buf[0])))
}

What did you see happen?

ICE during SSA lower (AMD64):

./main.go:12:21: internal compiler error: 'f': panic during lower while compiling f:

disjointTypes: one of arguments is not a pointer

goroutine 1 [running]:
cmd/compile/internal/ssa.Compile.func1()
	cmd/compile/internal/ssa/compile.go:49 +0x67
panic(...)
	runtime/panic.go:860 +0x13a
cmd/compile/internal/ssa.disjointTypes(...)
	cmd/compile/internal/ssa/rewrite.go:952 +0x159
cmd/compile/internal/ssa.disjoint(...)
	cmd/compile/internal/ssa/rewrite.go:913 +0x4d
cmd/compile/internal/ssa.isInlinableMemmove(...)
	cmd/compile/internal/ssa/rewrite.go:1482 +0xca
cmd/compile/internal/ssa.rewriteValueAMD64_OpSelectN(...)
	cmd/compile/internal/ssa/rewriteAMD64.go:75568 +0x34f
...

What did you expect to see?

Successful compile. Workaround: avoid copy for this path (byte loop + //go:noinline).

Possibly related to TBAA / disjointTypes (#80583), but this is a hard ICE on go1.26.2 windows/amd64.

Activity

  1. changed the title [-]cmd/compile: ICE disjointTypes during lower with unsafe.Slice/copy into [N]byte (go1.26.2 amd64)[/-] [+]cmd/compile: ICE disjointTypes on copy from unsafe.Slice(uintptr) into [N]byte (go1.26.2 amd64)[/+] on Sep 15, 2026
  2. thepudds commented on Sep 15, 2026

    @thepudds
    Member

    Hi @azusayn, this might be fixed:

      GOOD master: 8f5d820655 | 2026-09-15 06:35 | os,internal/poll: lazily initialize Windows NewFile handles
      first FIX:   c34b99a5e2 | 2026-02-05 19:50 | cmd/compile: CSE loads across disjoint stores
    
  3. azusayn commented on Sep 15, 2026

    @azusayn
    Author

    Thanks — works for me on gotip at 8f5d820.

  4. thepudds commented on Sep 15, 2026

    @thepudds
    Member

    Hi @azusayn, this also seems to work on Go 1.27.1, so I am going to close this as completed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    compiler/runtimeIssues related to the Go compiler and/or runtime.

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions