Skip to content

go/types, types2: type checker panics with unsafe.Sizeof #76384

@mrkfrmn

Description

@mrkfrmn

Consider:

import "unsafe"

type T [unsafe.Sizeof(f())]int

func f() T {
    return T{}
}

This yields:

testdata/manual.go:12:6  :  -- checking type T (objPath = )
testdata/manual.go:12:8  :  .  -- type [unsafe.Sizeof(f())]int
testdata/manual.go:12:22 :  .  .  -- expr unsafe.Sizeof(f())
testdata/manual.go:12:15 :  .  .  .  -- expr unsafe.Sizeof
testdata/manual.go:12:15 :  .  .  .  => unsafe.Sizeof (built-in)
testdata/manual.go:12:24 :  .  .  .  -- expr f()
testdata/manual.go:12:23 :  .  .  .  .  -- expr f
testdata/manual.go:14:6  :  .  .  .  .  .  -- checking func f (objPath = T)
testdata/manual.go:14:10 :  .  .  .  .  .  .  -- type T
testdata/manual.go:12:6  :  .  .  .  .  .  .  .  ## cycle detected: objPath = T->f->T (len = 2)
testdata/manual.go:12:6  :  .  .  .  .  .  .  .  ## cycle contains: 0 values, 1 type definitions
testdata/manual.go:12:6  :  .  .  .  .  .  .  .  => cycle is valid
testdata/manual.go:14:10 :  .  .  .  .  .  .  => T (under = <nil>) // *Named
testdata/manual.go:14:6  :  .  .  .  .  .  => func f() T
testdata/manual.go:12:23 :  .  .  .  .  => f (value of type func() T)
testdata/manual.go:12:24 :  .  .  .  => f() (value of array type T)
testdata/manual.go:12:22 :  .  .  => f() (value of array type T)
testdata/manual.go:12:8  :  .  => <nil> // <nil>
testdata/manual.go:12:6  :  => type T [0]<nil>
The following panic happened checking types near:
        testdata/manual.go:12:6
--- FAIL: TestManual (0.13s)
panic: runtime error: invalid memory address or nil pointer dereference [recovered, repanicked]
[signal SIGSEGV: segmentation violation code=0x2 addr=0x20 pc=0x10515e948]

goroutine 35 [running]:
testing.tRunner.func1.2({0x10547c920, 0x105505710})
        /Users/markfreeman/dev/go/src/testing/testing.go:1967 +0x1a0
testing.tRunner.func1()
        /Users/markfreeman/dev/go/src/testing/testing.go:1970 +0x318
panic({0x10547c920?, 0x105505710?})
        /Users/markfreeman/dev/go/src/runtime/panic.go:856 +0x12c
cmd/compile/internal/types2.(*Checker).handleBailout(0x502b38bc2000, 0x502b38d336f8)
        /Users/markfreeman/dev/go/src/cmd/compile/internal/types2/check.go:448 +0x228

Metadata

Metadata

Assignees

Labels

BugReportIssues describing a possible bug in the Go implementation.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions