From: Daniel Martí Date: Sun, 16 Dec 2018 17:44:31 +0000 (+0100) Subject: cmd/compile: don't crash on -d=ssa/ X-Git-Tag: go1.13beta1~1412 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=be9c534cdef07630606fde23344fc8a5d769a04e;p=gostls13.git cmd/compile: don't crash on -d=ssa/ I forgot how to pull up the ssa debug options help, so instead of writing -d=ssa/help, I just wrote -d=ssa/. Much to my amusement, the compiler just crashed, as shown below. Fix that. panic: runtime error: index out of range goroutine 1 [running]: cmd/compile/internal/ssa.PhaseOption(0x7ffc375d2b70, 0x0, 0xdbff91, 0x5, 0x1, 0x0, 0x0, 0x1, 0x1) /home/mvdan/tip/src/cmd/compile/internal/ssa/compile.go:327 +0x1876 cmd/compile/internal/gc.Main(0xde7bd8) /home/mvdan/tip/src/cmd/compile/internal/gc/main.go:411 +0x41d0 main.main() /home/mvdan/tip/src/cmd/compile/main.go:51 +0xab Change-Id: Ia2ad394382ddf8f4498b16b5cfb49be0317fc1aa Reviewed-on: https://go-review.googlesource.com/c/154421 Run-TryBot: Daniel Martí TryBot-Result: Gobot Gobot Reviewed-by: Keith Randall --- diff --git a/src/cmd/compile/internal/ssa/compile.go b/src/cmd/compile/internal/ssa/compile.go index 29618e29c3..38f12abf18 100644 --- a/src/cmd/compile/internal/ssa/compile.go +++ b/src/cmd/compile/internal/ssa/compile.go @@ -212,7 +212,8 @@ var BuildDump string // name of function to dump after initial build of ssa // BOOT_GO_GCFLAGS=-d='ssa/~^.*scc$/off' GO_GCFLAGS='-d=ssa/~^.*scc$/off' ./make.bash // func PhaseOption(phase, flag string, val int, valString string) string { - if phase == "help" { + switch phase { + case "", "help": lastcr := 0 phasenames := " check, all, build, intrinsics" for _, p := range passes { diff --git a/src/cmd/go/testdata/script/gcflags_patterns.txt b/src/cmd/go/testdata/script/gcflags_patterns.txt index f2e6e2b67d..c790ddda0a 100644 --- a/src/cmd/go/testdata/script/gcflags_patterns.txt +++ b/src/cmd/go/testdata/script/gcflags_patterns.txt @@ -27,6 +27,10 @@ stderr 'compile.* -e.* -p z1' go test -c -n -gcflags='all=-e' z1 stderr 'compile.* -e.* -p z3 ' +# this particular -gcflags argument made the compiler crash +! go build -gcflags=-d=ssa/ z1 +stderr 'PhaseOptions usage' + # -ldflags for implicit test package applies to test binary go test -c -n -gcflags=-N -ldflags=-X=x.y=z z1 stderr 'compile.* -N .*z_test.go'