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: compiler error when building a binary with race detector enabled #64606

Closed
tchung1118 opened this issue Dec 7, 2023 · 2 comments
Assignees
Labels
compiler/runtime Issues related to the Go compiler and/or runtime.

Comments

@tchung1118
Copy link

Go version

go version devel go1.22-bb34112d4d Thu Dec 7 17:27:54 2023 +0000 darwin/arm64

What operating system and processor architecture are you using (go env)?

GO111MODULE=''
GOARCH='arm64'
GOBIN=''
GOCACHE='/Users/taiwon/Library/Caches/go-build'
GOENV='/Users/taiwon/Library/Application Support/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFLAGS=''
GOHOSTARCH='arm64'
GOHOSTOS='darwin'
GOINSECURE=''
GOMODCACHE='/Users/taiwon/go/pkg/mod'
GONOPROXY=''
GONOSUMDB=''
GOOS='darwin'
GOPATH='/Users/taiwon/go'
GOPRIVATE=''
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/Users/taiwon/go/src/github.com/golang/go'
GOSUMDB='sum.golang.org'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/Users/taiwon/go/src/github.com/golang/go/pkg/tool/darwin_arm64'
GOVCS=''
GOVERSION='devel go1.22-bb34112d4d Thu Dec 7 17:27:54 2023 +0000'
GCCGO='gccgo'
AR='ar'
CC='clang'
CXX='clang++'
CGO_ENABLED='1'
GOMOD='/Users/taiwon/go/src/github.com/tchung1118/test-app/go.mod'
GOWORK=''
CGO_CFLAGS='-O2 -g'
CGO_CPPFLAGS=''
CGO_CXXFLAGS='-O2 -g'
CGO_FFLAGS='-O2 -g'
CGO_LDFLAGS='-O2 -g'
PKG_CONFIG='pkg-config'
GOGCCFLAGS='-fPIC -arch arm64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -ffile-prefix-map=/var/folders/t0/jhcv48q51ydbyzqn85y8rsgm0000gn/T/go-build3626636808373952552=/tmp/go-build -gno-record-gcc-switches -fno-common'

What did you do?

I have the following code:
main.go:

package main

import (
	"errors"
	"fmt"
)

func main() {

}

// ToFloat64 tries to convert an interface to int64
// it returns 0, error if failed
func ToFloat64(o interface{}) (float64, error) {
	switch v := o.(type) {
	case int:
		return float64(v), nil
	case int8:
		return float64(v), nil
	case int16:
		return float64(v), nil
	case int32:
		return float64(v), nil
	case int64:
		return float64(v), nil
	case float32:
		return float64(v), nil
	case float64:
		return float64(v), nil
	default:
		return float64(0), errors.New("Failed to convert to float64")
	}
}

func someFunc() {
	value, err := ToFloat64(int64(5))
	fmt.Println(value, err)

	value, err = ToFloat64(uint64(5))
	fmt.Println(value, err)
}

And I tried to build it with the following command:

~/go/src/github.com/golang/go/bin/go build -gcflags=-race .

What did you expect to see?

I expect the compilation to succeed. (succeeds in go1.21)

What did you see instead?

I see an internal compiler error with the following trace:

./main.go:36:25: internal compiler error: 'someFunc': inconsistent state, num predecessors: 7, num phi args: 7

goroutine 1 [running]:
runtime/debug.Stack()
        /Users/taiwon/go/src/github.com/golang/go/src/runtime/debug/stack.go:24 +0x64
cmd/compile/internal/base.FatalfAt({0x474ef8?, 0x140?}, {0x140005bf400, 0x40}, {0x14000627980, 0x3, 0x3})
        /Users/taiwon/go/src/github.com/golang/go/src/cmd/compile/internal/base/print.go:225 +0x1fc
cmd/compile/internal/base.Fatalf(...)
        /Users/taiwon/go/src/github.com/golang/go/src/cmd/compile/internal/base/print.go:194
cmd/compile/internal/ssagen.(*ssafn).Fatalf(0x0?, {0x5fedc0?, 0x140?}, {0x10566599b, 0x3a}, {0x140005fedc0, 0x2, 0x14000474f78?})
        /Users/taiwon/go/src/github.com/golang/go/src/cmd/compile/internal/ssagen/ssa.go:8225 +0x150
cmd/compile/internal/ssa.(*Func).Fatalf(0x140005da340, {0x10566599b, 0x3a}, {0x140005fedc0, 0x2, 0x2})
        /Users/taiwon/go/src/github.com/golang/go/src/cmd/compile/internal/ssa/func.go:742 +0x25c
cmd/compile/internal/ssa.(*Block).Fatalf(...)
        /Users/taiwon/go/src/github.com/golang/go/src/cmd/compile/internal/ssa/block.go:405
cmd/compile/internal/ssa.(*Block).removePhiArg(0x1400053bf50, 0x1400050e5b0, 0x4)
        /Users/taiwon/go/src/github.com/golang/go/src/cmd/compile/internal/ssa/block.go:342 +0xe0
cmd/compile/internal/ssa.(*Block).removeEdge(0x14000622bb0?, 0x6?)
        /Users/taiwon/go/src/github.com/golang/go/src/cmd/compile/internal/ssa/deadcode.go:331 +0x290
cmd/compile/internal/ssa.deadcode(0x140005da340)
        /Users/taiwon/go/src/github.com/golang/go/src/cmd/compile/internal/ssa/deadcode.go:181 +0x1614
cmd/compile/internal/ssa.Compile(0x140005da340)
        /Users/taiwon/go/src/github.com/golang/go/src/cmd/compile/internal/ssa/compile.go:97 +0x94c
cmd/compile/internal/ssagen.buildssa(0x14000470c60, 0x0)
        /Users/taiwon/go/src/github.com/golang/go/src/cmd/compile/internal/ssagen/ssa.go:575 +0x2150
cmd/compile/internal/ssagen.Compile(0x14000470c60, 0x0)
        /Users/taiwon/go/src/github.com/golang/go/src/cmd/compile/internal/ssagen/pgen.go:216 +0x30
cmd/compile/internal/gc.compileFunctions.func5.1(0x1?)
        /Users/taiwon/go/src/github.com/golang/go/src/cmd/compile/internal/gc/compile.go:182 +0x3c
cmd/compile/internal/gc.compileFunctions.func2(0x4?)
        /Users/taiwon/go/src/github.com/golang/go/src/cmd/compile/internal/gc/compile.go:136 +0x28
cmd/compile/internal/gc.compileFunctions.func5({0x140005fe920, 0x3, 0x1058874a0?})
        /Users/taiwon/go/src/github.com/golang/go/src/cmd/compile/internal/gc/compile.go:181 +0x60
cmd/compile/internal/gc.compileFunctions()
        /Users/taiwon/go/src/github.com/golang/go/src/cmd/compile/internal/gc/compile.go:192 +0x1f4
cmd/compile/internal/gc.Main(0x105887330)
        /Users/taiwon/go/src/github.com/golang/go/src/cmd/compile/internal/gc/main.go:303 +0x1274
main.main()
        /Users/taiwon/go/src/github.com/golang/go/src/cmd/compile/main.go:57 +0x110
@gopherbot gopherbot added the compiler/runtime Issues related to the Go compiler and/or runtime. label Dec 7, 2023
@tchung1118 tchung1118 changed the title cmd/compile: compiler error when building a test binary with race detection on cmd/compile: compiler error when building a binary with race detector enabled Dec 7, 2023
@randall77 randall77 self-assigned this Dec 7, 2023
@randall77
Copy link
Contributor

@y1yang0 This looks like the failure is in the SCCP pass.

@gopherbot
Copy link
Contributor

Change https://go.dev/cl/548356 mentions this issue: cmd/compile: fix SCCP propagation into jump tables

ezz-no pushed a commit to ezz-no/go-ezzno that referenced this issue Feb 18, 2024
We can't delete all the outgoing edges and then add one back in, because
then we've lost the argument of any phi at the target. Instead, move
the important target to the front of the list and delete the rest.

This normally isn't a problem, because there is never normally a phi
at the target of a jump table. But this isn't quite true when in race
build mode, because there is a phi of the result of a bunch of raceread
calls.

The reason this happens is that each case is written like this (where e
is the runtime.eface we're switching on):

if e.type == $type.int32 {
   m = raceread(e.data, m1)
}
m2 = phi(m1, m)
if e.type == $type.int32 {
   .. do case ..
   goto blah
}

so that if e.type is not $type.int32, it falls through to the default
case. This default case will have a memory phi for all the (jumped around
and not actually called) raceread calls.

If we instead did it like

if e.type == $type.int32 {
  raceread(e.data)
  .. do case ..
  goto blah
}

That would paper over this bug, as it is the only way to construct
a jump table whose target is a block with a phi in it. (Yet.)

But we'll fix the underlying bug in this CL. Maybe we can do the
rewrite mentioned above later.  (It is an optimization for -race mode,
which isn't particularly important.)

Fixes golang#64606

Change-Id: I6f6e3c90eb1e2638112920ee2e5b6581cef04ea4
Reviewed-on: https://go-review.googlesource.com/c/go/+/548356
Reviewed-by: Keith Randall <[email protected]>
Reviewed-by: David Chase <[email protected]>
LUCI-TryBot-Result: Go LUCI <[email protected]>
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.
Projects
None yet
Development

No branches or pull requests

3 participants