Skip to content

gollvm/gofrontend: when evaluates x twice in "x op= y", which was detectable if evaluating y affects x. #52811

Closed
@xqq0629

Description

@xqq0629

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

$ go version

gollvm

Does this issue reproduce with the latest release?

yes

What operating system and processor architecture are you using (go env)?

go env Output
$ go env


Debian
Intel(R) Xeon(R) Platinum 8260 CPU @ 2.40GHz (Cascade Lake)

What did you do?

error case:

package main
import "fmt"
func mapscase() int {
    one := map[int]int{0: 1299}
    two := map[int]int{0: 2388}

    x := one
    x[0] += func() int {
        x = two
        return 1113
    }()

    return two[0]
}

func main() {
    a := mapscase()
    fmt.Println(a)
}

What did you expect to see?

3501

What did you see instead?

2412
cmd/compile: "x[i] op= y" evaluates x[i] more than once can also be referenced.

Error & Solution

An output of 2412 indicates that x[0] was evaluated twice as follows: once indexing into the old map to read the value 1299, and then once into the new to store the value 1299 + 1113.

gofrontend doesn't consider such case: when evaluates x twice in "x op= y", evaluating y may affect x. In such case, y on the right should be evaluated first and x on the left should be read latter.

Metadata

Metadata

Assignees

No one assigned

    Labels

    FrozenDueToAgeNeedsFixThe path to resolution is known, but the work has not been done.

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions