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: mismatched mem #60990

Closed
ALTree opened this issue Jun 25, 2023 · 2 comments
Closed

cmd/compile: internal compiler error: mismatched mem #60990

ALTree opened this issue Jun 25, 2023 · 2 comments
Assignees
Labels
compiler/runtime Issues related to the Go compiler and/or runtime. NeedsFix The path to resolution is known, but the work has not been done. release-blocker
Milestone

Comments

@ALTree
Copy link
Member

ALTree commented Jun 25, 2023

 ~/go/bin/go version
go version devel go1.21-a031f4e Sat Jun 24 05:24:25 2023 +0000 linux/amd64
$ tree
.
├── a
│   ├── a.go
│   └── go.mod
├── go.mod
└── main.go

(zipped tree attached below).

a.go

package a

import "reflect"

type T struct{ _, _ []int }

func F[_ int]() {
	var f0, f1 float64
	var b bool
	_ = func(T, float64) bool {
		b = reflect.DeepEqual(0, 1)
		return func() bool {
			f1 = min(f0, 0)
			return b
		}()
	}(T{nil, nil}, min(0, f1))
	f0 = min(0, 1)
}

main.go

package main

import "a"

func main() {
	a.F[int]()
}
$ ~/go/bin/go build main.go

# command-line-arguments
./a/a.go:18:1: internal compiler error: 'F[go.shape.int]': Op...LECall and OpDereference have mismatched mem, v24 = StaticLECall <bool,mem> {AuxCall{a.F[go.shape.int].func1}} [88] v14 v15 v16 v5 v18 v23 v22 and v18 = Dereference <a.T> v17 v13

goroutine 21 [running]:
runtime/debug.Stack()
	/home/alberto/go/src/runtime/debug/stack.go:24 +0x5e
cmd/compile/internal/base.FatalfAt({0x584df8?, 0xc0?}, {0xc00013c2d0, 0x42}, {0xc0003fe600, 0x3, 0x3})
	/home/alberto/go/src/cmd/compile/internal/base/print.go:230 +0x1d7
cmd/compile/internal/base.Fatalf(...)
	/home/alberto/go/src/cmd/compile/internal/base/print.go:199
cmd/compile/internal/ssagen.(*ssafn).Fatalf(0x10?, {0x757165b8?, 0x7f55?}, {0xd962d3, 0x3c}, {0xc0003f6700, 0x2, 0x0?})
	/home/alberto/go/src/cmd/compile/internal/ssagen/ssa.go:7994 +0x16a
cmd/compile/internal/ssa.(*Func).Fatalf(0xc000175860, {0xd962d3, 0x3c}, {0xc0003f6700, 0x2, 0x2})
	/home/alberto/go/src/cmd/compile/internal/ssa/func.go:716 +0x279
cmd/compile/internal/ssa.(*expandState).rewriteArgs(0xc000585800, 0xc0004e9100, 0x0)
	/home/alberto/go/src/cmd/compile/internal/ssa/expand_calls.go:1103 +0x545
cmd/compile/internal/ssa.expandCalls(0xc000175860)
	/home/alberto/go/src/cmd/compile/internal/ssa/expand_calls.go:1247 +0x408b
cmd/compile/internal/ssa.Compile(0xc000175860)
	/home/alberto/go/src/cmd/compile/internal/ssa/compile.go:97 +0x9ab
cmd/compile/internal/ssagen.buildssa(0xc0003bfe40, 0x3)
	/home/alberto/go/src/cmd/compile/internal/ssagen/ssa.go:568 +0x2b09
cmd/compile/internal/ssagen.Compile(0xc0003bfe40, 0x0?)
	/home/alberto/go/src/cmd/compile/internal/ssagen/pgen.go:187 +0x45
cmd/compile/internal/gc.compileFunctions.func5.1(0xc0003b3a40?)
	/home/alberto/go/src/cmd/compile/internal/gc/compile.go:184 +0x34
cmd/compile/internal/gc.compileFunctions.func3.1()
	/home/alberto/go/src/cmd/compile/internal/gc/compile.go:166 +0x30
created by cmd/compile/internal/gc.compileFunctions.func3 in goroutine 20
	/home/alberto/go/src/cmd/compile/internal/gc/compile.go:165 +0x23a

crash.zip

cc @randall77

@ALTree ALTree added NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. compiler/runtime Issues related to the Go compiler and/or runtime. labels Jun 25, 2023
@cuonglm
Copy link
Member

cuonglm commented Jun 26, 2023

Simpler reproducer:

package p

type T struct{ _, _ []int }

func F[_ int]() {
	var f0, f1 float64
	var b bool
	_ = func(T, float64) bool {
		b = deepEqual(0, 1)
		return func() bool {
			f1 = min(f0, 0)
			return b
		}()
	}(T{nil, nil}, min(0, f1))
	f0 = min(0, 1)
}

//go:noinline
func deepEqual(x, y any) bool {
	return x == y
}

func init() {
	F[int]()
}

@cuonglm cuonglm added NeedsFix The path to resolution is known, but the work has not been done. release-blocker and removed NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. labels Jun 26, 2023
@cuonglm cuonglm added this to the Go1.21 milestone Jun 26, 2023
@cuonglm cuonglm self-assigned this Jun 26, 2023
@gopherbot
Copy link

Change https://go.dev/cl/506115 mentions this issue: cmd/compile: fix bad order of evaluation for min/max builtin

bradfitz pushed a commit to tailscale/go that referenced this issue Jul 15, 2023
For float or string, min/max builtin performs a runtime call, so we need
to save its result to temporary variable. Otherwise, the runtime call
will clobber closure's arguments currently on the stack when passing
min/max as argument to closures.

Fixes golang#60990

Change-Id: I1397800f815ec7853182868678d0f760b22afff2
Reviewed-on: https://go-review.googlesource.com/c/go/+/506115
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
Run-TryBot: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Auto-Submit: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Reviewed-by: Cherry Mui <cherryyz@google.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compiler/runtime Issues related to the Go compiler and/or runtime. NeedsFix The path to resolution is known, but the work has not been done. release-blocker
Projects
None yet
Development

No branches or pull requests

3 participants