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: ineffective branch caused by defer #32930

Open
mariecurried opened this issue Jul 3, 2019 · 2 comments
Open

cmd/compile: ineffective branch caused by defer #32930

mariecurried opened this issue Jul 3, 2019 · 2 comments
Labels
compiler/runtime Issues related to the Go compiler and/or runtime. NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone

Comments

@mariecurried
Copy link

What version of Go are you using (go version)?

$ go version
go version devel +d410642 Mon Jul 1 21:30:23 2019 +0000 linux/amd64

Does this issue reproduce with the latest release?

Yes.

What did you do?

I was testing the behavior of defer, so I ended up compiling the following functions (https://godbolt.org/z/uALdNA):

package test

func f() {
}

func usef() {
    defer f()
}

What did you expect to see?

I expected the generated assembly to not contain any unnecessary branches.

What did you see instead?

Instead, there is a repeated block of instructions that is preceded by a condicional jump (https://godbolt.org/z/uALdNA):

        testl   AX, AX
        jne     applyf_pc83
        xchgl   AX, AX
        call    runtime.deferreturn(SB)
        movq    64(SP), BP
        addq    $72, SP
        ret
applyf_pc83:
        xchgl   AX, AX
        call    runtime.deferreturn(SB)
        movq    64(SP), BP
        addq    $72, SP
        ret
@ianlancetaylor
Copy link
Contributor

CC @randall77

@dmitshur dmitshur added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Jul 4, 2019
@dmitshur dmitshur added this to the Go1.14 milestone Jul 4, 2019
@randall77
Copy link
Contributor

This is known. One return path is the normal return path, and one is the panic/recover return path. Each has a call to deferreturn. We don't share epilogues at the moment, see #24936 for some discussion.

In any case, this bug will probably become obsolete once we fix #14939.

But I'll leave this open for now. I couldn't find an issue explicitly about epilogue sharing (which this is), so might as well use this one.

@rsc rsc modified the milestones: Go1.14, Backlog Oct 9, 2019
@gopherbot gopherbot added the compiler/runtime Issues related to the Go compiler and/or runtime. label Jul 13, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compiler/runtime Issues related to the Go compiler and/or runtime. NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
Status: Triage Backlog
Development

No branches or pull requests

6 participants