| 1 |
// run |
| 2 |
|
| 3 |
// Copyright 2026 The Go Authors. All rights reserved. |
| 4 |
// Use of this source code is governed by a BSD-style |
| 5 |
// license that can be found in the LICENSE file. |
| 6 |
|
| 7 |
// Issue 79182: SHLQconst/SHLLconst rewrite rule for (x+x)<<c |
| 8 |
// missed a bounds check on c, causing c+1 to overflow the valid |
| 9 |
// shift range and producing incorrect results on amd64. |
| 10 |
|
| 11 |
package main |
| 12 |
|
| 13 |
//go:noinline |
| 14 |
func shl32(x uint32) uint32 { |
| 15 |
return (x + x) << 31 |
| 16 |
} |
| 17 |
|
| 18 |
//go:noinline |
| 19 |
func shl64(x uint64) uint64 { |
| 20 |
return (x + x) << 63 |
| 21 |
} |
| 22 |
|
| 23 |
func main() { |
| 24 |
if got := shl32(1); got != 0 { |
| 25 |
println("shl32(1) =", got, "want 0") |
| 26 |
panic("FAIL") |
| 27 |
} |
| 28 |
if got := shl64(1); got != 0 { |
| 29 |
println("shl64(1) =", got, "want 0") |
| 30 |
panic("FAIL") |
| 31 |
} |
| 32 |
} |