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: internal compiler error: incomplete itab #49421

Closed
mpx opened this issue Nov 7, 2021 · 3 comments
Closed

cmd/compile: internal compiler error: incomplete itab #49421

mpx opened this issue Nov 7, 2021 · 3 comments
Labels
NeedsInvestigation release-blocker
Milestone

Comments

@mpx
Copy link
Contributor

@mpx mpx commented Nov 7, 2021

The following code snippet generates an internal compiler error with tip:

// Fails on:
// go version devel +61d789db3a Sat Nov 6 19:41:15 2021 +0000 linux/amd64
package main

func main() {
    var a, b foo
    bar(a, b)
}

type foo int

func (a foo) less(b foo) bool {
    return a < b
}

type lesser[T any] interface {
    less(T) bool
    comparable
}

func bar[T lesser[T]](a, b T) {
    a.less(b)
}   

Stack trace:

# bug
<autogenerated>:1: internal compiler error: incomplete itab

goroutine 1 [running]:
runtime/debug.Stack()
        /home/build/go-devel/src/runtime/debug/stack.go:24 +0x65
cmd/compile/internal/base.FatalfAt({0x5a6850?, 0xc0?}, {0xd1b230, 0xf}, {0x0, 0x0, 0x0})
        /home/build/go-devel/src/cmd/compile/internal/base/print.go:227 +0x1ca
cmd/compile/internal/base.Fatalf(...)
        /home/build/go-devel/src/cmd/compile/internal/base/print.go:196
cmd/compile/internal/reflectdata.writeITab(0xc0000c6880, 0xc0005a6850, 0xc0005c09a0)
        /home/build/go-devel/src/cmd/compile/internal/reflectdata/reflect.go:1315 +0x4b0
cmd/compile/internal/reflectdata.ITabLsym(0xc0005c09a0?, 0xc0005a5520?)
        /home/build/go-devel/src/cmd/compile/internal/reflectdata/reflect.go:856 +0x19c
cmd/compile/internal/noder.(*genInst).finalizeSyms(0x1384d60)
        /home/build/go-devel/src/cmd/compile/internal/noder/stencil.go:1753 +0x64d
cmd/compile/internal/noder.(*genInst).buildInstantiations(0x1384d60, 0x1)
        /home/build/go-devel/src/cmd/compile/internal/noder/stencil.go:76 +0xb0
cmd/compile/internal/noder.BuildInstantiations(...)
        /home/build/go-devel/src/cmd/compile/internal/noder/stencil.go:47
cmd/compile/internal/noder.(*irgen).generate(0xc0005b8000, {0xc000074a60, 0x2, 0x203000?})
        /home/build/go-devel/src/cmd/compile/internal/noder/irgen.go:320 +0x3db
cmd/compile/internal/noder.check2({0xc000074a60, 0x2, 0x2})
        /home/build/go-devel/src/cmd/compile/internal/noder/irgen.go:92 +0x16d
cmd/compile/internal/noder.LoadPackage({0xc00001e220, 0x2, 0x0?})
        /home/build/go-devel/src/cmd/compile/internal/noder/noder.go:90 +0x335
cmd/compile/internal/gc.Main(0xd44290)
        /home/build/go-devel/src/cmd/compile/internal/gc/main.go:191 +0xb13
main.main()
        /home/build/go-devel/src/cmd/compile/main.go:55 +0xdd

This example builds successfully with the unified experiment.

@ALTree ALTree added the NeedsInvestigation label Nov 7, 2021
@ALTree ALTree added this to the Go1.18 milestone Nov 7, 2021
@gopherbot
Copy link

@gopherbot gopherbot commented Nov 7, 2021

Change https://golang.org/cl/361959 mentions this issue: cmd/compile: adjust the order for skip "==" in sigs of iface

@zhouguangyuan0718
Copy link
Contributor

@zhouguangyuan0718 zhouguangyuan0718 commented Nov 7, 2021

func writeITab(lsym *obj.LSym, typ, iface *types.Type) {

In the function writeITab, the "==" in sigs will be skiped . But if "==" is the first element in sigs. It can't be skiped by the code before my CL.
And if we only add some code skip it before and after the loop, (like patchset2:https://go-review.googlesource.com/c/go/+/361959/2). It can be build successfully, but run crash. Because the offset of other method in itab is wrong.
For the code in this issue:

"".main STEXT size=63 args=0x0 locals=0x18 funcid=0x0 align=0x0
        …………
        0x001b 00027 (issue49421.go:26) LEAQ    ""..dict.bar["".foo](SB), CX
        0x0022 00034 (issue49421.go:26) PCDATA  $0, $-1
        0x0022 00034 (issue49421.go:26) MOVQ    32(CX), CX
        0x0026 00038 (issue49421.go:26) MOVQ    32(CX), CX
        0x002a 00042 (issue49421.go:26) XORL    BX, BX
        0x002c 00044 (issue49421.go:26) CALL    CX
        …………
        rel 30+4 t=14 ""..dict.bar["".foo]+0
        …………
………………
go.itab."".foo,"".lesser["".foo] SRODATA dupok size=32
        0x0000 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
        0x0010 5e 13 7f 18 00 00 00 00 00 00 00 00 00 00 00 00  ^...............
        rel 0+8 t=1 type."".lesser["".foo]+0
        rel 8+8 t=1 type."".foo+0
        rel 24+8 t=-32767 "".(*foo).less+0
""..dict.bar["".foo] SRODATA dupok size=40
        0x0000 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
        0x0010 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
        0x0020 00 00 00 00 00 00 00 00                          ........
        rel 0+8 t=1 type."".foo+0
        rel 0+0 t=23 type."".foo+0
        rel 0+0 t=23 type.func("".foo) bool+0
        rel 8+8 t=1 type."".lesser["".foo]+0
        rel 16+8 t=1 type.func("".foo) bool+0
        rel 32+8 t=1 go.itab."".foo,"".lesser["".foo]+0

The offset of "".(*foo).less in go.itab."".foo,"".lesser["".foo] is 24, but in function main, it use offset 32 in 0x0026.

@gopherbot
Copy link

@gopherbot gopherbot commented Nov 8, 2021

Change https://golang.org/cl/361962 mentions this issue: cmd/compile: do not expand methods of comparable interface

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
NeedsInvestigation release-blocker
Projects
None yet
Development

No branches or pull requests

4 participants