Skip to content

gccgo: -O1/2 generates an incorrect behavior #19806

Closed
@trex58

Description

@trex58

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

Activity

ALTree

ALTree commented on Mar 31, 2017

@ALTree
Member

(I've edited your message to fix a few formatting problems).

added
NeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.
on Mar 31, 2017
added this to the Gccgo milestone on Mar 31, 2017
changed the title [-]gccgo -O1/2 generates an incorrect behavior[/-] [+]gccgo: -O1/2 generates an incorrect behavior[/+] on Mar 31, 2017
ianlancetaylor

ianlancetaylor commented on Mar 31, 2017

@ianlancetaylor
Contributor

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

gopherbot commented on Feb 1, 2018

@gopherbot
Contributor

Change https://golang.org/cl/91275 mentions this issue: compiler: check for nil receiver in value method

added a commit that references this issue on Feb 1, 2018
1288505
locked and limited conversation to collaborators on Feb 1, 2019
added a commit that references this issue on May 16, 2022
22149e3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    FrozenDueToAgeNeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @ianlancetaylor@ALTree@trex58@gopherbot

        Issue actions

          gccgo: -O1/2 generates an incorrect behavior · Issue #19806 · golang/go