1 // Copyright 2014 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
5 // This file contains tests for the suspicious shift checker.
16 _ = (i8 + 1) << 8 // want ".i8 . 1. .8 bits. too small for shift of 8"
17 _ = i8 << (7 + 1) // want "i8 .8 bits. too small for shift of 8"
18 _ = i8 >> 8 // want "i8 .8 bits. too small for shift of 8"
19 i8 <<= 8 // want "i8 .8 bits. too small for shift of 8"
20 i8 >>= 8 // want "i8 .8 bits. too small for shift of 8"
23 _ = i16 << 16 // want "i16 .16 bits. too small for shift of 16"
24 _ = i16 >> 16 // want "i16 .16 bits. too small for shift of 16"
25 i16 <<= 16 // want "i16 .16 bits. too small for shift of 16"
26 i16 >>= 16 // want "i16 .16 bits. too small for shift of 16"
29 _ = i32 << 32 // want "i32 .32 bits. too small for shift of 32"
30 _ = i32 >> 32 // want "i32 .32 bits. too small for shift of 32"
31 i32 <<= 32 // want "i32 .32 bits. too small for shift of 32"
32 i32 >>= 32 // want "i32 .32 bits. too small for shift of 32"
35 _ = i64 << 64 // want "i64 .64 bits. too small for shift of 64"
36 _ = i64 >> 64 // want "i64 .64 bits. too small for shift of 64"
37 i64 <<= 64 // want "i64 .64 bits. too small for shift of 64"
38 i64 >>= 64 // want "i64 .64 bits. too small for shift of 64"
41 _ = u8 << 8 // want "u8 .8 bits. too small for shift of 8"
42 _ = u8 >> 8 // want "u8 .8 bits. too small for shift of 8"
43 u8 <<= 8 // want "u8 .8 bits. too small for shift of 8"
44 u8 >>= 8 // want "u8 .8 bits. too small for shift of 8"
47 _ = u16 << 16 // want "u16 .16 bits. too small for shift of 16"
48 _ = u16 >> 16 // want "u16 .16 bits. too small for shift of 16"
49 u16 <<= 16 // want "u16 .16 bits. too small for shift of 16"
50 u16 >>= 16 // want "u16 .16 bits. too small for shift of 16"
53 _ = u32 << 32 // want "u32 .32 bits. too small for shift of 32"
54 _ = u32 >> 32 // want "u32 .32 bits. too small for shift of 32"
55 u32 <<= 32 // want "u32 .32 bits. too small for shift of 32"
56 u32 >>= 32 // want "u32 .32 bits. too small for shift of 32"
59 _ = u64 << 64 // want "u64 .64 bits. too small for shift of 64"
60 _ = u64 >> 64 // want "u64 .64 bits. too small for shift of 64"
61 u64 <<= 64 // want "u64 .64 bits. too small for shift of 64"
62 u64 >>= 64 // want "u64 .64 bits. too small for shift of 64"
63 _ = u64 << u64 // Non-constant shifts should succeed.
67 const in = 8 * unsafe.Sizeof(i)
68 _ = i << in // want "too small for shift"
69 _ = i >> in // want "too small for shift"
70 i <<= in // want "too small for shift"
71 i >>= in // want "too small for shift"
72 const ix = 8*unsafe.Sizeof(i) - 1
80 const un = 8 * unsafe.Sizeof(u)
81 _ = u << un // want "too small for shift"
82 _ = u >> un // want "too small for shift"
83 u <<= un // want "too small for shift"
84 u >>= un // want "too small for shift"
85 const ux = 8*unsafe.Sizeof(u) - 1
93 const pn = 8 * unsafe.Sizeof(p)
94 _ = p << pn // want "too small for shift"
95 _ = p >> pn // want "too small for shift"
96 p <<= pn // want "too small for shift"
97 p >>= pn // want "too small for shift"
98 const px = 8*unsafe.Sizeof(p) - 1
104 const oneIf64Bit = ^uint(0) >> 63 // allow large shifts of constants; they are used for 32/64 bit compatibility tricks
107 h = h<<8 | (h >> (8 * (unsafe.Sizeof(h) - 1)))
108 h <<= 8 * unsafe.Sizeof(h) // want "too small for shift"
109 h >>= 7 * unsafe.Alignof(h)
110 h >>= 8 * unsafe.Alignof(h) // want "too small for shift"
113 func ShiftDeadCode() {
115 const iBits = 8 * unsafe.Sizeof(i)
153 _ = i << 64 // want "too small for shift"