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 RHS operand type for shift= statements #52342

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

x/tools/go/ssa: bad RHS operand type for shift= statements #52342

mdempsky opened this issue Apr 14, 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

Compiling

func F() {
	var d int8
	d >>= 1000
}

with x/tools/go/ssa produces:

func F():
0:                                                                entry P:0 S:0
	t0 = 0:int8 >> 1000:int8                                           int8
	return

See https://go.dev/play/p/XugtNClNWNp?v=gotip

But a 1000:int8 constant is ill typed, because 1000 is out of range for int8. Moreover, there's no reason 1000 needs to be int8, it's fine as uint.

Notably, if the code is changed to d = d >> 1000, then the 1000 constant is correctly typed as uint.

I think the fix is in builder.assignOp: it should only apply b.emitConv(val, oldv.Type()) when op isn't LSH or RSH. When it is a shift, it should just use val as is.

/cc @timothy-king @zpavlinovic

@mdempsky mdempsky added the NeedsFix The path to resolution is known, but the work has not been done. label Apr 14, 2022
@gopherbot gopherbot added the Tools This label describes issues relating to any tools in the x/tools repository. label Apr 14, 2022
@gopherbot gopherbot added this to the Unreleased milestone Apr 14, 2022
mdempsky added a commit to despiteallobjections/amigo that referenced this issue Apr 14, 2022
Discovered an x/tools/go/ssa bug in the process: golang/go#52342.
@mdempsky mdempsky self-assigned this Apr 14, 2022
@gopherbot
Copy link

Change https://go.dev/cl/400394 mentions this issue: go/ssa: fix miscompilation of <<= and >>= statements

@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

2 participants