Skip to content

cmd/compile: internal compiler error: panic: invalid memory address #79274

Closed

Description

@ALTree
$ gotip version
go version go1.27-devel_e30b75a910 Thu May 7 22:44:49 2026 -0700 linux/amd64
package main

import "math/big"

func F() {
        var pg0_0 *int
        _ = pg0_0
        var u16_0 uint16
        fnc := func(a [0][][3]int, b [14][9]uint16, c []big.Int) uint16 {
                pg0_0 = func() *int { return nil }()
                return 0
        }

        fnc([0][][3]int{}, [14][9]uint16{[9]uint16{fnc([0][][3]int{}, [14][9]uint16{[9]uint16{min(fnc([0][][3]int{}, [14][9]uint16{[9]uint16{(uint16)(16), (uint16)(93), (uint16)(31)}, [9]uint16{(uint16)(5), (uint16)(69)}, [9]uint16{}}, []big.Int{}), u16_0), fnc([0][][3]int{}, [14][9]uint16{}, nil)}, [9]uint16{fnc([0][][3]int{}, [14][9]uint16{}, nil)}, [9]uint16{}}, nil), 0}}, nil)
}

func main() {
        F()
}
$ gotip build crash.go

# command-line-arguments
./crash.go:10:25: internal compiler error: panic: runtime error: invalid memory address or nil pointer dereference

goroutine 1 [running]:
runtime/debug.Stack()
        ./gotip/src/runtime/debug/stack.go:26 +0x5e
cmd/compile/internal/base.FatalfAt({0xaadbd628?, 0x3a3f?}, {0xf46620, 0x9}, {0x3a3faadbd658, 0x1, 0x1})
        ./gotip/src/cmd/compile/internal/base/print.go:232 +0x18b
cmd/compile/internal/base.Fatalf(...)
        ./gotip/src/cmd/compile/internal/base/print.go:197
cmd/compile/internal/gc.handlePanic()
        ./gotip/src/cmd/compile/internal/gc/main.go:57 +0x90
panic({0x1867460?, 0x19519d0?})
        ./gotip/src/runtime/panic.go:859 +0x125
cmd/internal/obj.(*Link).InitTextSym(...)
        ./gotip/src/cmd/internal/obj/plist.go:186
...

Activity

  1. added
    NeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.
    on May 8, 2026
  2. cuonglm commented on May 8, 2026

    @cuonglm
    Member

    git bisect points to 409f784

  3. dims commented on May 8, 2026

    @dims
    Contributor

    here's another angle to this bug perhaps? The crash seems to also happen when two different files contain the same tiny function call at the same line and column. That suggests the compiler is accidentally treating them as the same generated function because it uses line/column information but not the filename.

    #!/usr/bin/env bash
    set -euo pipefail
    
    d="$(mktemp -d "${TMPDIR:-/tmp}/gotip-ice.XXXXXX")"
    
    cat >"$d/a.go" <<'EOF'
    package p; var _ = F(); func F() func() { return func() {} }
    EOF
    
    cat >"$d/b.go" <<'EOF'
    package p; var _ = F()
    EOF
    
    echo "workdir: $d"
    gotip version
    gotip tool compile "$d/a.go" "$d/b.go"

    the output is:

    ❯ /tmp/repro-gotip-closure-inline-ice.sh
    workdir: /var/folders/2x/b5xl9skd2fl0l6tj54fjxh540000gp/T//gotip-ice.TdvPYe
    go version go1.27-devel_e30b75a9 Thu May 7 22:44:49 2026 -0700 darwin/arm64
    /var/folders/2x/b5xl9skd2fl0l6tj54fjxh540000gp/T//gotip-ice.TdvPYe/a.go:1:50: internal compiler error: panic: runtime error: invalid memory address or nil pointer dereference
    
    goroutine 1 [running]:
    runtime/debug.Stack()
            /Users/dsrinivas/sdk/gotip/src/runtime/debug/stack.go:26 +0x64
    cmd/compile/internal/base.FatalfAt({0x4f42d5c8?, 0x1935?}, {0x100f61b3e, 0x9}, {0x19354f42d5f8, 0x1, 0x1})
            /Users/dsrinivas/sdk/gotip/src/cmd/compile/internal/base/print.go:232 +0x210
    cmd/compile/internal/base.Fatalf(...)
            /Users/dsrinivas/sdk/gotip/src/cmd/compile/internal/base/print.go:197
    cmd/compile/internal/gc.handlePanic()
            /Users/dsrinivas/sdk/gotip/src/cmd/compile/internal/gc/main.go:57 +0x8c
    panic({0x10185d2d8?, 0x101948980?})
            /Users/dsrinivas/sdk/gotip/src/runtime/panic.go:859 +0x120
    cmd/internal/obj.(*Link).InitTextSym(...)
            /Users/dsrinivas/sdk/gotip/src/cmd/internal/obj/plist.go:186
    cmd/compile/internal/ir.setupTextLSym(0x19354f9be3a0?, 0x101b0b201?)
            /Users/dsrinivas/sdk/gotip/src/cmd/compile/internal/ir/abi.go:77 +0x268
    cmd/compile/internal/ir.InitLSym(0x19354f88a8c0, 0x1)
            /Users/dsrinivas/sdk/gotip/src/cmd/compile/internal/ir/abi.go:32 +0xf0
    cmd/compile/internal/gc.prepareFunc(0x19354f88a8c0)
            /Users/dsrinivas/sdk/gotip/src/cmd/compile/internal/gc/compile.go:104 +0x24
    cmd/compile/internal/gc.enqueueFunc(0x19354f88a8c0, 0x19354f42dba0)
            /Users/dsrinivas/sdk/gotip/src/cmd/compile/internal/gc/compile.go:85 +0x2d0
    cmd/compile/internal/gc.Main(0x1018c3028)
            /Users/dsrinivas/sdk/gotip/src/cmd/compile/internal/gc/main.go:333 +0x12e8
    main.main()
            /Users/dsrinivas/sdk/gotip/src/cmd/compile/main.go:57 +0xfc
    

    Started looking at it as kubernetes has CI jobs that use golang tip and they are broken:
    kubernetes/kubernetes#138891

  4. dims commented on May 8, 2026

    @dims
    Contributor

    @cuonglm here's a fix that seems to work! (add more context to the hash like the source file and inling tree index)

    diff --git a/src/cmd/compile/internal/ir/func.go b/src/cmd/compile/internal/ir/func.go
    index 7990310423..af05d50803 100644
    --- a/src/cmd/compile/internal/ir/func.go
    +++ b/src/cmd/compile/internal/ir/func.go
    @@ -14,6 +14,7 @@ import (
            "encoding/base64"
            "fmt"
            "io"
    +       "strconv"
            "unicode/utf8"
     )
    
    @@ -471,11 +472,17 @@ func closureName(outerfn *Func, pos src.XPos, why Op, gen int) *types.Sym {
                    // it will not be the linker symbol name. For linking,
                    // we use a content hash to disambiguate instead.
                    // We choose the suffix as a hash of the inline call stack.
    +               // Include the source filename, since distinct files can have
    +               // calls with the same function name, line, and column, and the
    +               // inlining tree index, since it is the compiler's unique identity
    +               // for this inlined call.
                    h := hash.New32()
                    io.WriteString(h, outer)
                    base.Ctxt.InlTree.AllParents(inlIndex, func(call obj.InlinedCall) {
    -                       io.WriteString(h, call.Name+":"+call.Pos.LineNumber()+":"+call.Pos.ColumnNumber())
    +                       pos := base.Ctxt.InnermostPos(call.Pos)
    +                       io.WriteString(h, ":"+call.Name+":"+pos.Filename()+":"+pos.LineNumber()+":"+strconv.FormatUint(uint64(pos.Col()), 10))
                    })
    +               h.Write([]byte(":" + strconv.Itoa(inlIndex)))
                    inlHash = base64.StdEncoding.EncodeToString(h.Sum(nil)[:8])
    
                    outer = base.Ctxt.InlTree.InlinedFuncName(inlIndex)
    
  5. mark-rushakoff commented on May 8, 2026

    @mark-rushakoff
    Contributor

    I believe I've run into the same panic when compiling https://github.com/gabriel-vasile/mimetype as a dependency of a different project.

    go version go1.27-devel_afcf04cb64 Fri May 8 05:51:09 2026 -0700 darwin/arm64

    $ gotip test ./...
    # github.com/gabriel-vasile/mimetype/internal/magic
    ../../../../pkg/mod/github.com/gabriel-vasile/mimetype@v1.4.3/internal/magic/magic.go:161:3: internal compiler error: panic: runtime error: invalid memory address or nil pointer dereference
    
    goroutine 1 [running]:
    runtime/debug.Stack()
    	../../../..tip/src/github.com/golang/go/src/runtime/debug/stack.go:26 +0x64
    cmd/compile/internal/base.FatalfAt({0xa1fa95c8?, 0x1a0?}, {0x104b41b3e, 0x9}, {0x1a0a1fa95f8, 0x1, 0x1})
    	../../../..tip/src/github.com/golang/go/src/cmd/compile/internal/base/print.go:232 +0x210
    cmd/compile/internal/base.Fatalf(...)
    	../../../..tip/src/github.com/golang/go/src/cmd/compile/internal/base/print.go:197
    cmd/compile/internal/gc.handlePanic()
    	../../../..tip/src/github.com/golang/go/src/cmd/compile/internal/gc/main.go:57 +0x8c
    panic({0x1054412d0?, 0x10552c9a0?})
    	../../../..tip/src/github.com/golang/go/src/runtime/panic.go:859 +0x120
    cmd/internal/obj.(*Link).InitTextSym(...)
    	../../../..tip/src/github.com/golang/go/src/cmd/internal/obj/plist.go:186
    cmd/compile/internal/ir.setupTextLSym(0x1a0a1980008?, 0x1a0a2dc8501?)
    	../../../..tip/src/github.com/golang/go/src/cmd/compile/internal/ir/abi.go:77 +0x268
    cmd/compile/internal/ir.InitLSym(0x1a0a28a03c0, 0x1)
    	../../../..tip/src/github.com/golang/go/src/cmd/compile/internal/ir/abi.go:32 +0xf0
    cmd/compile/internal/gc.prepareFunc(0x1a0a28a03c0)
    	../../../..tip/src/github.com/golang/go/src/cmd/compile/internal/gc/compile.go:104 +0x24
    cmd/compile/internal/gc.enqueueFunc(0x1a0a1eb8640, 0x1a0a1fa9ba0)
    	../../../..tip/src/github.com/golang/go/src/cmd/compile/internal/gc/compile.go:85 +0x2d0
    cmd/compile/internal/gc.Main(0x1054a7008)
    	../../../..tip/src/github.com/golang/go/src/cmd/compile/internal/gc/main.go:333 +0x12e8
    main.main()
    	../../../..tip/src/github.com/golang/go/src/cmd/compile/main.go:57 +0xfc
    

    Permalink to the source line: https://github.com/gabriel-vasile/mimetype/blob/e64d6bdb3607578757d31380818651a9fc95ca8b/internal/magic/magic.go#L163

  6. gopherbot commented on May 8, 2026

    @gopherbot
    Contributor

    Change https://go.dev/cl/775900 mentions this issue: cmd/compile: fix duplicated inlining hash for closures

  7. added this to the Go1.27 milestone on May 8, 2026
  8. gopherbot commented on May 8, 2026

    @gopherbot
    Contributor

    Change https://go.dev/cl/775624 mentions this issue: cmd/compile: use inline tree index to identify call stack

  9. self-assigned this
    on May 9, 2026
  10. added a commit that references this issue on May 9, 2026
    ce4fc94
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

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.release-blocker

Type

No type

Projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions