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

x/tools/go/ssa: bad order of evaluation with slice expressions #52142

Closed
mdempsky opened this issue Apr 4, 2022 · 1 comment
Closed

x/tools/go/ssa: bad order of evaluation with slice expressions #52142

mdempsky opened this issue Apr 4, 2022 · 1 comment
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done. Tools This label describes issues relating to any tools in the x/tools repository.
Milestone

Comments

@mdempsky
Copy link
Member

mdempsky commented Apr 4, 2022

This function:

func F(s []int, f, g func() int) []int { return s[f():g()] }

should invoke f() before g(), because it's lexically to the left. But when compiled with x/tools/go/ssa, it gives the opposite order:

func F(s []int, f func() int, g func() int) []int:
0:                                                                entry P:0 S:0
	t0 = g()                                                            int
	t1 = f()                                                            int
	t2 = slice s[t1:t0]                                               []int
	return t2

https://go.dev/play/p/aY22d2R-3Zw

I think this is simply because the ast.SliceExpr case in builder.expr visits e.High before e.Low.

/cc @timothy-king @zpavlinovic @findleyr

@mdempsky mdempsky added the NeedsFix The path to resolution is known, but the work has not been done. label Apr 4, 2022
@gopherbot gopherbot added the Tools This label describes issues relating to any tools in the x/tools repository. label Apr 4, 2022
@gopherbot gopherbot added this to the Unreleased milestone Apr 4, 2022
mdempsky added a commit to despiteallobjections/amigo that referenced this issue Apr 4, 2022
@timothy-king timothy-king self-assigned this Apr 4, 2022
@gopherbot
Copy link

Change https://go.dev/cl/398057 mentions this issue: go/ssa: emit Low expression before High in *ast.Slice

@golang golang locked and limited conversation to collaborators Jun 22, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done. Tools This label describes issues relating to any tools in the x/tools repository.
Projects
None yet
Development

No branches or pull requests

3 participants