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: misrepresents the dynamic behavior of shift with signed rhs #51363

Closed
dominikh opened this issue Feb 25, 2022 · 2 comments
Closed
Labels
Analysis Issues related to static analysis (vet, x/tools/go/analysis) 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

@dominikh
Copy link
Member

Input:

package main

func foo(x int) { _ = 1 << x }
func main()     { foo(-1) }

Output:

func foo(x int):
0:                                                                entry P:0 S:0
	t0 = convert uint64 <- int (x)                                   uint64
	t1 = 1:int << t0                                                    int
	return

Actual runtime behavior:

$ go run bar.go                                                                
panic: runtime error: negative shift amount

This issue is very similar to #50949, with much of the same possible fixes.

/cc @timothy-king

@dominikh dominikh added NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. Tools This label describes issues relating to any tools in the x/tools repository. Analysis Issues related to static analysis (vet, x/tools/go/analysis) labels Feb 25, 2022
@gopherbot gopherbot added this to the Unreleased milestone Feb 25, 2022
@timothy-king
Copy link
Contributor

Thanks. Confirmed this is a bug.

The relevant code is here: https://cs.opensource.google/go/x/tools/+/refs/tags/v0.1.9:go/ssa/emit.go;l=76-80

@timothy-king timothy-king added NeedsFix The path to resolution is known, but the work has not been done. and removed NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. labels Feb 25, 2022
@gopherbot
Copy link

Change https://go.dev/cl/387995 mentions this issue: go/ssa: allows right operand of a shift to be signed.

@golang golang locked and limited conversation to collaborators Feb 26, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Analysis Issues related to static analysis (vet, x/tools/go/analysis) 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