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 error for math.Sqrt as statement rather than expression #16804

Closed
ghost opened this issue Aug 19, 2016 · 6 comments
Closed
Milestone

Comments

@ghost
Copy link

ghost commented Aug 19, 2016

go version go1.7 darwin/amd64

https://play.golang.org/p/ERICb8NpYL
Don't actually run the playground, this is just the content of the file, make a file called whatever_test.go and try to test it.

    ./a_test.go:10: internal compiler error: unhandled stmt SQRT

    goroutine 1 [running]:
    runtime/debug.Stack(0x0, 0x0, 0x0)
        /usr/local/go/src/runtime/debug/stack.go:24 +0x79
    cmd/compile/internal/gc.Fatalf(0x4fc74c, 0x11, 0xc420456f20, 0x1, 0x1)
        /usr/local/go/src/cmd/compile/internal/gc/subr.go:165 +0x15d
    cmd/compile/internal/gc.(*ssaExport).Unimplementedf(0x75e786, 0xa, 0x4fc74c, 0x11, 0xc420456f20, 0x1, 0x1)
        /usr/local/go/src/cmd/compile/internal/gc/ssa.go:4446 +0x13e
    cmd/compile/internal/ssa.(*Config).Unimplementedf(0xc4204be000, 0xc40000000a, 0x4fc74c, 0x11, 0xc420456f20, 0x1, 0x1)
        /usr/local/go/src/cmd/compile/internal/ssa/config.go:202 +0x71
    cmd/compile/internal/gc.(*state).Unimplementedf(0xc4200e2240, 0x4fc74c, 0x11, 0xc420456f20, 0x1, 0x1)
        /usr/local/go/src/cmd/compile/internal/gc/ssa.go:338 +0x83
    cmd/compile/internal/gc.(*state).stmt(0xc4200e2240, 0xc4204b3e60)
        /usr/local/go/src/cmd/compile/internal/gc/ssa.go:967 +0x9fd
    cmd/compile/internal/gc.(*state).stmts(0xc4200e2240, 0xc4204a3500)
        /usr/local/go/src/cmd/compile/internal/gc/ssa.go:535 +0x5e
    cmd/compile/internal/gc.(*state).stmt(0xc4200e2240, 0xc4204b3d40)
        /usr/local/go/src/cmd/compile/internal/gc/ssa.go:891 +0x17c8
    cmd/compile/internal/gc.(*state).stmts(0xc4200e2240, 0xc4204a35a0)
        /usr/local/go/src/cmd/compile/internal/gc/ssa.go:535 +0x5e
    cmd/compile/internal/gc.buildssa(0xc4204b35f0, 0x0)
        /usr/local/go/src/cmd/compile/internal/gc/ssa.go:182 +0x6c0
    cmd/compile/internal/gc.compile(0xc4204b35f0)
        /usr/local/go/src/cmd/compile/internal/gc/pgen.go:405 +0x1377
    cmd/compile/internal/gc.funccompile(0xc4204b35f0)
        /usr/local/go/src/cmd/compile/internal/gc/dcl.go:1287 +0x186
    cmd/compile/internal/gc.Main()
        /usr/local/go/src/cmd/compile/internal/gc/main.go:467 +0x19f8
    cmd/compile/internal/amd64.Main()
        /usr/local/go/src/cmd/compile/internal/amd64/galign.go:93 +0x2fa
    main.main()
        /usr/local/go/src/cmd/compile/main.go:33 +0x2a3```
@ianlancetaylor ianlancetaylor changed the title go test fails to execute simple test cmd/compile: internal error for math.Sqrt as statement rather than expression Aug 19, 2016
@ianlancetaylor ianlancetaylor modified the milestones: Go1.7.1, Go1.8 Aug 19, 2016
@ianlancetaylor
Copy link
Contributor

Simpler replication:

package main

import (
    "math"
)

func main() {
    math.Sqrt(10)
}

Works if the line in the function is

_ = math.Sqrt(10)

I initially marked this as 1.7.1, but considering that the statement is useless, dropping to 1.8.

CC @randall77 @josharian

@md2perpe
Copy link

Bug verified under go version go1.7 windows/amd64.

@josharian
Copy link
Contributor

Should be a straightforward fix. Perhaps @odeke-em @kevinburke or @martisch (or anyone else getting up to speed on the compiler who I might have missed) wants to try their hand? Leave a note here first so you don't collide with each other. :)

@josharian
Copy link
Contributor

Note also (as Ian observes) that the only possible purpose of the statement is to evaluate the internal expression for side effects, so there's no need to generate an actual additional SSA value.

@martisch
Copy link
Contributor

martisch commented Aug 20, 2016

seems:

case OSQRT:
    s.expr(n.Left)

in ssa.go should suffice. Will mail a full CL later.

@gopherbot
Copy link

CL https://golang.org/cl/27437 mentions this issue.

@golang golang locked and limited conversation to collaborators Aug 21, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants