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: crash when compiling function named "_" #29870

Closed
alandonovan opened this issue Jan 22, 2019 · 7 comments
Closed

cmd/compile: crash when compiling function named "_" #29870

alandonovan opened this issue Jan 22, 2019 · 7 comments
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone

Comments

@alandonovan
Copy link
Contributor

alandonovan commented Jan 22, 2019

$ go version
go version devel +cad6d1fef5 Mon Jan 21 23:31:09 2019 +0000 linux/amd64
$ cat test/test.go 
package test

import "log"

func a() {
        log.Println("%2F")
}
$ go build test
$ sed -i -e 's/func a/func _/' test/test.go
$ go build test
# test
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x60 pc=0xc4e259]

goroutine 50 [running]:
cmd/compile/internal/gc.emitStackObjects(0xc000538000, 0xc0005ea0e0)
        ~/goroot/src/cmd/compile/internal/gc/ssa.go:5057 +0x1c9
cmd/compile/internal/gc.genssa(0xc00053c000, 0xc0005ea0e0)
        ~/goroot/src/cmd/compile/internal/gc/ssa.go:5092 +0xe1
cmd/compile/internal/gc.compileSSA(0xc0000cc420, 0x1)
        ~/goroot/src/cmd/compile/internal/gc/pgen.go:301 +0x378
cmd/compile/internal/gc.compileFunctions.func2(0xc0004fcf60, 0xc0004fe1d0, 0x1)
        ~/goroot/src/cmd/compile/internal/gc/pgen.go:356 +0x49
created by cmd/compile/internal/gc.compileFunctions
        ~/goroot/src/cmd/compile/internal/gc/pgen.go:354 +0x129
@bcmills bcmills added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Jan 22, 2019
@bcmills
Copy link
Contributor

bcmills commented Jan 22, 2019

CC @randall77 @josharian @martisch

@bcmills bcmills added this to the Go1.13 milestone Jan 22, 2019
@randall77 randall77 self-assigned this Jan 22, 2019
@gopherbot
Copy link

Change https://golang.org/cl/158845 mentions this issue: cmd/compile: don't bother compiling functions named "_"

@randall77
Copy link
Contributor

This was introduced as part of adding stack objects. Fix out for review.

Do we care about functions named "_"? Is there any legitimate use for them? If so, we should fix this in 1.12. If not, we can leave for 1.13.

@bcmills
Copy link
Contributor

bcmills commented Jan 22, 2019

I could imagine someone using them to contain static assertions: that is, a function named _ that fails to compile if certain conditions (such as equality of sizes) are not met.

I don't know whether anyone does that in practice.

@alandonovan
Copy link
Contributor Author

I could imagine someone using them to contain static assertions.

Exactly. They must be type-checked, but there's no need to generate code for them.

@eliasnaur eliasnaur reopened this Jan 22, 2019
@gopherbot
Copy link

Change https://golang.org/cl/158820 mentions this issue: cmd/compile: don't bother compiling functions named "_"

@randall77
Copy link
Contributor

The latter CL is for 1.12. The former CL has more clean up in it and will go in for 1.13.

gopherbot pushed a commit that referenced this issue Jan 22, 2019
They can't be used, so we don't need code generated for them. We just
need to report errors in their bodies.

This is the minimal CL for 1.12. For 1.13, CL 158845 will remove
a bunch of special cases sprinkled about the compiler to handle "_"
functions, which should (after this CL) be unnecessary.

Update #29870

Change-Id: Iaa1c194bd0017dffdce86589fe2d36726ee83c13
Reviewed-on: https://go-review.googlesource.com/c/158820
Run-TryBot: Keith Randall <khr@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
@golang golang locked and limited conversation to collaborators Feb 26, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
None yet
Development

No branches or pull requests

5 participants