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: walkExpr: switch 1 unknown op RECOVER #51839

Closed
ahazhangxin opened this issue Mar 21, 2022 · 9 comments
Closed
Labels
NeedsFix
Milestone

Comments

@ahazhangxin
Copy link

@ahazhangxin ahazhangxin commented Mar 21, 2022

What version of Go are you using (go version)?

$ go version
go version go1.18 darwin/amd64

Does this issue reproduce with the latest release?

it is already the latest version

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

go env Output
$ go env
GO111MODULE="on"
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/zhangxin/Library/Caches/go-build"
GOENV="/Users/zhangxin/Library/Application Support/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOINSECURE=""
GOMODCACHE="/Users/zhangxin/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="darwin"
GOPATH="/Users/zhangxin/go"
GOPROXY="https://goproxy.io,direct"
GOROOT="/usr/local/Cellar/go/1.18/libexec"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/Cellar/go/1.18/libexec/pkg/tool/darwin_amd64"
GOVCS=""
GOVERSION="go1.18"
GCCGO="gccgo"
GOAMD64="v1"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOWORK=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -arch x86_64 -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/dg/2q4522bs3959p0x7tbn61_kw0000gn/T/go-build3463372418=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

go func() { defer func() { if r := recover(); r != nil { glog.Errorf("error=%v", r) } }() }

it seems fixed in https://go-review.googlesource.com/c/go/+/342350/
but in this version it appears again

What did you expect to see?

compiles correctly

What did you see instead?

walk . RECOVER INTER-interface {} tc(1) # hello_dao.go:50:21 hello_dao.go:50:21: internal compiler error: walkExpr: switch 1 unknown op RECOVER

@ahazhangxin ahazhangxin changed the title affected/package: cmd/compile: desugar ORECOVER into ORECOVERFP Mar 21, 2022
@ahazhangxin ahazhangxin changed the title cmd/compile: desugar ORECOVER into ORECOVERFP affected/package: cmd/compile Mar 21, 2022
@mvdan
Copy link
Member

@mvdan mvdan commented Mar 21, 2022

Could you please provide a full program to reproduce this crash?

@mvdan mvdan changed the title affected/package: cmd/compile cmd/compile: internal compiler error: walkExpr: switch 1 unknown op RECOVER Mar 21, 2022
@ahazhangxin
Copy link
Author

@ahazhangxin ahazhangxin commented Mar 21, 2022

package main

import (
	"runtime"
	"sync"

	"github.com/golang/glog"
)

var prefetchOnce sync.Once

func testRecover() {
	if "darwin" != runtime.GOOS {
		prefetchOnce.Do(func() {
			go func() {
				defer func() {
					err := recover()
					if err != nil {
						//fmt.Println(err)
						glog.Errorf("error=%v", err)
					}
				}()
			}()
		})
	}
}

func main() {
	testRecover()
}

when i use go build test.go

# command-line-arguments
walk
.   RECOVER INTER-interface {} tc(1) # test.go:17:20
./test.go:17:20: internal compiler error: walkExpr: switch 1 unknown op RECOVER

Please file a bug report including a short program that triggers the error.
https://go.dev/issue/new

@hopehook
Copy link
Contributor

@hopehook hopehook commented Mar 21, 2022

A simple demo:

package main

func main() {
	testRecover()

}

func testRecover() {
	if false {
		func() {
			defer func() {
				_ = recover()
			}()
		}()
	}
}

@cuonglm cuonglm added the NeedsFix label Mar 21, 2022
@cuonglm cuonglm self-assigned this Mar 21, 2022
@cuonglm cuonglm added this to the Go1.19 milestone Mar 21, 2022
@gopherbot
Copy link

@gopherbot gopherbot commented Mar 21, 2022

Change https://go.dev/cl/394079 mentions this issue: cmd/compile: fix panic with nested dead hidden closures

@cuonglm
Copy link
Member

@cuonglm cuonglm commented Mar 21, 2022

Not sure this is qualified for backporting, since when the runtime.GOOS checking is likely to happen so often in user code. A workaround can be moving the code for specific OS to separated file, instead of checking for runtime.GOOS.

cc @mdempsky @cherrymui

@mvdan
Copy link
Member

@mvdan mvdan commented Mar 21, 2022

I do think this should be backported if possible, as it's a regression with a seemingly small fix.

@ianlancetaylor
Copy link
Contributor

@ianlancetaylor ianlancetaylor commented Mar 21, 2022

@gopherbot Please open backport to 1.18

This is an internal compiler error on valid code.

@gopherbot
Copy link

@gopherbot gopherbot commented Mar 21, 2022

Backport issue(s) opened: #51846 (for 1.18).

Remember to create the cherry-pick CL(s) as soon as the patch is submitted to master, according to https://go.dev/wiki/MinorReleases.

@ianlancetaylor
Copy link
Contributor

@ianlancetaylor ianlancetaylor commented Mar 21, 2022

CC @randall77

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

No branches or pull requests

6 participants