-
Notifications
You must be signed in to change notification settings - Fork 18k
gccgo: -O1/2 generates an incorrect behavior #19806
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
Comments
(I've edited your message to fix a few formatting problems). |
The problem is that we need to add an explicit nil test in the stub generated for a pointer type to call a value method. The test case fails because the value method does not refer to the receiver, so the copy from the pointer receiver to a value is eliminated when optimizing. |
Change https://golang.org/cl/91275 mentions this issue: |
We already dereference the pointer to copy the value, but if the method does not use the value then the pointer dereference may be optimized away. Do an explicit nil check so that we get the panic that is required. Fixes golang/go#19806 Reviewed-on: https://go-review.googlesource.com/91275 * go.go-torture/execute/printnil.go: New test. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@257280 138bc75d-0d04-0410-961f-82ee72b054a4
We already dereference the pointer to copy the value, but if the method does not use the value then the pointer dereference may be optimized away. Do an explicit nil check so that we get the panic that is required. Fixes golang/go#19806 Reviewed-on: https://go-review.googlesource.com/91275 * go.go-torture/execute/printnil.go: New test. From-SVN: r257280
Please answer these questions before submitting your issue. Thanks!
What version of Go are you using (
go version
)?$ gccgo --version
gccgo (GCC) 7.0.1 20170309
$ rpm -qa | grep gcc-go
gcc-go-7.0.1-0.12.fc25.x86_64
What operating system and processor architecture are you using (
go env
)?$ uname -a
Linux dorado-vm1 4.8.6-300.fc25.x86_64 #1 SMP Tue Nov 1 12:36:38 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux
What did you do?
$ cat main.go
package main
import "fmt"
type MyType struct {
val int
}
func (t MyType) String() string {
return "foobar"
}
func main() {
fmt.Printf("%s\n", (*MyType)(nil))
}
$ gccgo -O2 main.go ; ./a.out
What did you expect to see?
Go Lang:
$ go version
go version go1.8 linux/amd64
$ go run main.go
<nil>
GccGo:
$ gccgo -O0 main.go ; ./a.out
<nil>
What did you see instead?
$ gccgo -O2 main.go ; ./a.out
foobar
$ gccgo -O1 main.go ; ./a.out
foobar
The text was updated successfully, but these errors were encountered: