Closed
Description
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
Metadata
Metadata
Assignees
Labels
Type
Projects
Milestone
Relationships
Development
No branches or pull requests
Activity
ALTree commentedon Mar 31, 2017
(I've edited your message to fix a few formatting problems).
[-]gccgo -O1/2 generates an incorrect behavior[/-][+]gccgo: -O1/2 generates an incorrect behavior[/+]ianlancetaylor commentedon Mar 31, 2017
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.
gopherbot commentedon Feb 1, 2018
Change https://golang.org/cl/91275 mentions this issue:
compiler: check for nil receiver in value method
compiler: check for nil receiver in value method
compiler: check for nil receiver in value method