Skip to content

cmd/compile: internal compiler error: bad type: struct #81241

Closed

Description

@YuanchengJiang

The following code:

package main
import (
	"reflect"
)
func intPtrTypeKind() reflect.Kind {
	return reflect.TypeFor[*int]().Kind()
}
type large struct {
	large_d430158
	b [1500000000]byte
}
type large_d430158 struct {
	b [1500000000]byte
}

Resulted in this output:

# fflreduce
./main.go:12:6: internal compiler error: bad type: struct { large_d430158; b [1500000000]byte }

goroutine 1 [running]:
runtime/debug.Stack()
	/home/fuzz/WorkSpace/fusion-fuzz/projects/go/go-src/src/runtime/debug/stack.go:26 +0x5e
cmd/compile/internal/base.FatalfAt({0x1ccfdc0?, 0x0?}, {0x103add2, 0xc}, {0x3bc9129eeaa8, 0x1, 0x1})
	/home/fuzz/WorkSpace/fusion-fuzz/projects/go/go-src/src/cmd/compile/internal/base/print.go:232 +0x18b
cmd/compile/internal/base.Fatalf(...)
	/home/fuzz/WorkSpace/fusion-fuzz/projects/go/go-src/src/cmd/compile/internal/base/print.go:197
cmd/compile/internal/types.typePos(0x59682f00?)
	/home/fuzz/WorkSpace/fusion-fuzz/projects/go/go-src/src/cmd/compile/internal/types/size.go:54 +0x90
cmd/compile/internal/types.calcStructOffset(0x3bc912a0e9c0, {0x3bc91250fcb0, 0x2, 0x1?}, 0x1?)
	/home/fuzz/WorkSpace/fusion-fuzz/projects/go/go-src/src/cmd/compile/internal/types/size.go:193 +0x111
cmd/compile/internal/types.CalcStructSize(...)
	/home/fuzz/WorkSpace/fusion-fuzz/projects/go/go-src/src/cmd/compile/internal/types/size.go:522
cmd/compile/internal/types.CalcSize(0x3bc912a0e9c0)
	/home/fuzz/WorkSpace/fusion-fuzz/projects/go/go-src/src/cmd/compile/internal/types/size.go:420 +0xa25
cmd/compile/internal/types.ResumeCheckSize()
	/home/fuzz/WorkSpace/fusion-fuzz/projects/go/go-src/src/cmd/compile/internal/types/size.go:721 +0x65
cmd/compile/internal/noder.(*pkgReader).objIdxMayFail(0x3bc9129bc1c0, 0x5, {0x0, 0x0, 0x0}, {0x1d10160, 0x0, 0x0}, 0x0)
	/home/fuzz/WorkSpace/fusion-fuzz/projects/go/go-src/src/cmd/compile/internal/noder/reader.go:855 +0x82a
cmd/compile/internal/noder.(*pkgReader).objIdx(...)
	/home/fuzz/WorkSpace/fusion-fuzz/projects/go/go-src/src/cmd/compile/internal/noder/reader.go:684
cmd/compile/internal/noder.(*pkgReader).objInstIdx(0x3bc9129bc1c0, {0x6?, {0x3bc9129ef258?, 0x3bc9129bc1c0?, 0x3bc912504ae0?}}, 0x0, 0x0)
	/home/fuzz/WorkSpace/fusion-fuzz/projects/go/go-src/src/cmd/compile/internal/noder/reader.go:676 +0x8f
cmd/compile/internal/noder.(*reader).obj(0x3bc9125194a0)
	/home/fuzz/WorkSpace/fusion-fuzz/projects/go/go-src/src/cmd/compile/internal/noder/reader.go:646 +0x13c
cmd/compile/internal/noder.(*reader).pkgObjs(0x3bc9125194a0, 0x3bc9126b4240)
	/home/fuzz/WorkSpace/fusion-fuzz/projects/go/go-src/src/cmd/compile/internal/noder/reader.go:3684 +0x9b
cmd/compile/internal/noder.(*reader).pkgDecls(0x3bc9125194a0, 0x3bc9126b4240)
	/home/fuzz/WorkSpace/fusion-fuzz/projects/go/go-src/src/cmd/compile/internal/noder/reader.go:3673 +0x194
cmd/compile/internal/noder.(*reader).pkgInit(0x3bc9125194a0, 0x3bc9126bb8b0?, 0x3bc9126b4240)
	/home/fuzz/WorkSpace/fusion-fuzz/projects/go/go-src/src/cmd/compile/internal/noder/reader.go:3537 +0xee
cmd/compile/internal/noder.unified({0x0?, {0x0?, 0x0?}}, {0x3bc9124dc6e8?, 0x197aba0?, 0x1b53b98?})
	/home/fuzz/WorkSpace/fusion-fuzz/projects/go/go-src/src/cmd/compile/internal/noder/unified.go:206 +0x1f9
cmd/compile/internal/noder.LoadPackage({0x3bc9124fc270, 0x1, 0x1})
	/home/fuzz/WorkSpace/fusion-fuzz/projects/go/go-src/src/cmd/compile/internal/noder/noder.go:76 +0x525
cmd/compile/internal/gc.Main(0x1a77de0)
	/home/fuzz/WorkSpace/fusion-fuzz/projects/go/go-src/src/cmd/compile/internal/gc/main.go:219 +0xd05
main.main()
	/home/fuzz/WorkSpace/fusion-fuzz/projects/go/go-src/src/cmd/compile/main.go:57 +0x105


To reproduce:

GOOS=linux GOARCH=386 go build .

Compiler version:

go version go1.28-devel_603439a1 Fri Aug 28 21:44:26 2026 -0700 linux/amd64

Commit:

603439a1c6f2d37c7f02e246342847056ed04c21

Build configuration:

cd src && ./make.bash (GOROOT_BOOTSTRAP=go1.26.0)

Operating System:

Ubuntu 22.04 Host, Docker fusion-fuzz-go:latest

This bug was found by fusion-fuzz

Activity

  1. thepudds commented on Aug 31, 2026

    @thepudds
    Member

    The reflect.TypeFor does not seem to be required.

    Also, FWIW, this does not seem to be a recently introduced problem. Not sure yet how far back it goes, but stepped back as far as 2022-08-27 and still able to reproduce it (though that required deleting the reflect.TypeFor because that API was not yet introduced at that time.).

    An actual bisect kicking off shortly...

  2. added
    NeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.
    on Aug 31, 2026
  3. dr2chase commented on Aug 31, 2026

    @dr2chase
    Contributor

    @golang/compiler

  4. cuonglm commented on Aug 31, 2026

    @cuonglm
    Member

    The reflect.TypeFor does not seem to be required.

    Also, FWIW, this does not seem to be a recently introduced problem. Not sure yet how far back it goes, but stepped back as far as 2022-08-27 and still able to reproduce it (though that required deleting the reflect.TypeFor because that API was not yet introduced at that time.).

    An actual bisect kicking off shortly...

    I believe this was broken between go1.17 and go1.18

  5. thepudds commented on Aug 31, 2026

    @thepudds
    Member

    This bisected to when Unified IR type parameters and types2 were enabled in c991278:

    Bisect successful:
      first BAD:   c9912780ab3e | 2021-08-21 00:24 | cmd/compile: enable -G=3 by default
      GOOD parent: 97d17dc02398 | 2021-08-20 21:00 | test/typeparam: add a test case for issue46591
    

    (That's with the reflect.TypeFor removed).

    I could go further back to see what commit in the type parameters work it happened (probably), but for now, I'll leave it as "not a recent problem" as the main conclusion.

    edit: sorry, I mis-remembered what -G=3 was for. It was for enabling the types2 type checker and support for type parameters, not the Unified IR work.

  6. griesemer commented on Aug 31, 2026

    @griesemer
    Contributor

    Simpler reproducer:

    package p
    type large struct {
    	a, b [1 << 30]byte
    }

    and then compile with

    GOOS=linux GOARCH=386 go tool compile <filename>
    

    A cursory investigation shows that the compiler correctly wants to report that the struct size is too large (for x386) via cmd/compile/internal/types/size.go:193 but that (for some reason) the position of t is unknown, which leads to the fatal error on line 54 in the same file rather than a proper error message.

    The position of t is unknown because t.obj is nil. In fact, t.obj is nil (almost?) always when accessed in Type.Pos (cmd/compile/internal/types/type.go:279).

  7. changed the title [-]ICE: bad type: struct[/-] [+]cmd/compile: internal compiler error: bad type: struct[/+] on Aug 31, 2026
  8. thepudds commented on Aug 31, 2026

    @thepudds
    Member

    Hi Robert, I can't promise this is useful info, but restarting the bisect with -G=3 seemed to land on 2427f6e:

      first BAD:   2427f6e6c0 | 2021-01-21 01:25 | cmd/compile: directly set some simple expression types
      GOOD parent: 455c29af83 | 2021-01-21 01:24 | cmd/compile/internal/types2: convert untyped arguments to delete
    

    (That's with GOARCH=386 go build -gcflags=all=-G=3 run on linux/amd64.)

  9. gopherbot commented on Aug 31, 2026

    @gopherbot
    Contributor

    Change https://go.dev/cl/825164 mentions this issue: cmd/compile: use field position for "struct too large" error

  10. griesemer commented on Aug 31, 2026

    @griesemer
    Contributor

    The CL above fixed the internal compiler error. Also, filed #81257 to follow up. Closing.

  11. griesemer commented on Aug 31, 2026

    @griesemer
    Contributor

    @thepudds Thanks for the bisect! This looks useful for #81257 as it seems that there's something larger amiss or not well understood anymore.

  12. added this to the Go1.28 milestone on Sep 15, 2026
  13. added
    NeedsFixThe path to resolution is known, but the work has not been done.
    and removed
    NeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.
    on Sep 15, 2026
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

    NeedsFixThe path to resolution is known, but the work has not been done.compiler/runtimeIssues related to the Go compiler and/or runtime.

    Type

    No type

    Projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions