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 crash with -m -h #31638

bradfitz opened this issue Apr 23, 2019 · 2 comments


None yet
3 participants
Copy link

commented Apr 23, 2019

Just hit this compiler crash....

bradfitz@go:~/go/src/unicode/utf8$ go version
go version devel +8515d9cf65 Tue Apr 23 17:58:12 2019 +0000 linux/amd64

bradfitz@go:~/go/src/unicode/utf8$ git di
diff --git a/src/unicode/utf8/utf8.go b/src/unicode/utf8/utf8.go
index db845ab2f2..b2b5308311 100644
--- a/src/unicode/utf8/utf8.go
+++ b/src/unicode/utf8/utf8.go
@@ -147,10 +147,19 @@ func FullRuneInString(s string) bool {
 // out of range, or is not the shortest possible UTF-8 encoding for the
 // value. No other validation is performed.
 func DecodeRune(p []byte) (r rune, size int) {
-       n := len(p)
-       if n < 1 {
-               return RuneError, 0
+       if len(p) != 0 {
+               r = rune(p[0])
+               if r < 127 {
+                       size = 1
+                       return
+               }
+       return decodeRuneSlow(&p)
+func decodeRuneSlow(pp *[]byte) (r rune, size int) {
+       p := *pp
+       n := len(p)
        p0 := p[0]
        x := first[p0]
        if x >= as {

bradfitz@go:~/go/src/unicode/utf8$ go tool compile -m -h utf8.go
utf8.go:102:6: can inline FullRune
utf8.go:122:6: can inline FullRuneInString
utf8.go:454:6: can inline RuneStart
utf8.go:272:15: inlining call to RuneStart
utf8.go:312:15: inlining call to RuneStart
utf8.go:328:6: can inline RuneLen
utf8.go:522:6: can inline ValidRune
utf8.go:102:15: FullRune p does not escape
utf8.go:122:23: FullRuneInString s does not escape
utf8.go:160:21: decodeRuneSlow pp does not escape
utf8.go:149:17: DecodeRune p does not escape
utf8.go:206:25: DecodeRuneInString s does not escape
utf8.go:254:21: DecodeLastRune p does not escape
utf8.go:294:29: DecodeLastRuneInString s does not escape
utf8.go:348:17: EncodeRune p does not escape
utf8.go:380:16: RuneCount p does not escape
utf8.go:417:24: RuneCountInString s does not escape
utf8.go:457:12: Valid p does not escape
utf8.go:489:18: ValidString s does not escape
utf8.go:107:12: index bounds check elided
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0xc855cb]

goroutine 1 [running]:
        /home/bradfitz/go/src/cmd/compile/internal/gc/subr.go:99 +0x4b
cmd/compile/internal/gc.Warn(0xde8c59, 0x19, 0x0, 0x0, 0x0)
        /home/bradfitz/go/src/cmd/compile/internal/gc/subr.go:164 +0x64
cmd/compile/internal/gc.walkexpr(0xc00039cd00, 0xc0003355b0, 0xc00039a500)
        /home/bradfitz/go/src/cmd/compile/internal/gc/walk.go:1050 +0x6a35
cmd/compile/internal/gc.walkexpr(0xc00039cb80, 0xc0003355b0, 0x0)
        /home/bradfitz/go/src/cmd/compile/internal/gc/walk.go:642 +0x18f9
cmd/compile/internal/gc.walkstmt(0xc00039cb80, 0xc00039cd80)
        /home/bradfitz/go/src/cmd/compile/internal/gc/walk.go:159 +0xd94
cmd/compile/internal/gc.walkstmtlist(0xc00044e800, 0xa, 0x10)
        /home/bradfitz/go/src/cmd/compile/internal/gc/walk.go:79 +0x46
        /home/bradfitz/go/src/cmd/compile/internal/gc/walk.go:63 +0x3da
        /home/bradfitz/go/src/cmd/compile/internal/gc/pgen.go:235 +0x6b
        /home/bradfitz/go/src/cmd/compile/internal/gc/pgen.go:221 +0xc1
        /home/bradfitz/go/src/cmd/compile/internal/gc/main.go:668 +0x307a
        /home/bradfitz/go/src/cmd/compile/main.go:51 +0xac

/cc @josharian @mdempsky @griesemer


This comment has been minimized.

Copy link

commented Apr 23, 2019

For some reason the Warn function intentionally crashes the program if -h is given (unlike the Warnl function). Probably only errors should do that.

It looks like it has been that way since at least 2015.


This comment has been minimized.

Copy link

commented Apr 23, 2019

Change mentions this issue: cmd/compile: don't call hcrash in Warn

@gopherbot gopherbot closed this in 24513d3 Apr 23, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.