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: panicking composite literals not properly flushed to globals #4608

Open
DanielMorsing opened this Issue Jan 3, 2013 · 11 comments

Comments

Projects
None yet
3 participants
@DanielMorsing
Copy link
Contributor

DanielMorsing commented Jan 3, 2013

This program causes an inconsistent memory state:

package main

import "fmt"

type L struct {
        x, y int
}

var x L

func main() {
        foo(0)
        fmt.Println(x)
}

func foo(bar int) {
        defer func() {
                _ = recover()
        }()
        x = L{ 1, 1/bar}
}

The expected output from this program is {0 0}, but it outputs {1 0} instead.

Potential solution is evaluating the non-const parts of the literal into temporaries
before copying the static data.
@rsc

This comment has been minimized.

Copy link
Contributor

rsc commented Jan 4, 2013

Comment 1:

I am not convinced that the spec disallows this behavior. Perhaps it does.

Labels changed: added priority-later, removed priority-triage.

Status changed to Thinking.

@DanielMorsing

This comment has been minimized.

Copy link
Contributor Author

DanielMorsing commented Jan 5, 2013

Comment 2:

From the section on assignments:
"The assignment proceeds in two phases. First, the operands of index expressions and
pointer indirections (including implicit pointer indirections in selectors) on the left
and the expressions on the right are all evaluated in the usual order. Second, the
assignments are carried out in left-to-right order."
This seems to state that any evaluation must be completed before an assignment happens.
@rsc

This comment has been minimized.

Copy link
Contributor

rsc commented Mar 12, 2013

Comment 3:

Labels changed: added go1.1maybe, removed go1.1.

@robpike

This comment has been minimized.

Copy link
Contributor

robpike commented May 18, 2013

Comment 4:

Labels changed: added go1.2maybe, removed go1.1maybe.

@DanielMorsing

This comment has been minimized.

Copy link
Contributor Author

DanielMorsing commented Jul 27, 2013

Comment 5:

Are we finished thinking?
Considering how expensive it is to evaluate into variables, I think the current behavior
is ok, but I can't find any justification for it in the spec.
@rsc

This comment has been minimized.

Copy link
Contributor

rsc commented Jul 29, 2013

Comment 6:

Nope, still thinking. :-)
@rsc

This comment has been minimized.

Copy link
Contributor

rsc commented Jul 30, 2013

Comment 7:

Labels changed: added feature.

@rsc

This comment has been minimized.

Copy link
Contributor

rsc commented Sep 9, 2013

Comment 8:

Labels changed: added go1.3maybe, removed go1.2maybe.

@rsc

This comment has been minimized.

Copy link
Contributor

rsc commented Nov 27, 2013

Comment 9:

Labels changed: removed feature.

@rsc

This comment has been minimized.

Copy link
Contributor

rsc commented Dec 4, 2013

Comment 10:

Labels changed: added release-none, removed go1.3maybe.

@rsc

This comment has been minimized.

Copy link
Contributor

rsc commented Dec 4, 2013

Comment 11:

Labels changed: added repo-main.

@rsc rsc added this to the Unplanned milestone Apr 10, 2015

@rsc rsc changed the title cmd/gc: panicking composite literals not properly flushed to globals cmd/compile: panicking composite literals not properly flushed to globals Jun 8, 2015

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.