Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(1082)

Delta Between Two Patch Sets: cmd/vet/testdata/shift.go

Issue 134780043: code review 134780043: go.tools/cmd/vet: detect suspicious shifts
Left Patch Set: diff -r 067839d7eb9b000c390a79f2f24a5b0e6975f574 https://code.google.com/p/go.tools Created 9 years, 7 months ago
Right Patch Set: diff -r 067839d7eb9b000c390a79f2f24a5b0e6975f574 https://code.google.com/p/go.tools Created 9 years, 7 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « cmd/vet/shift.go ('k') | no next file » | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
1 // Copyright 2014 The Go Authors. All rights reserved. 1 // Copyright 2014 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style 2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file. 3 // license that can be found in the LICENSE file.
4 4
5 // This file contains tests for the suspicious shift checker. 5 // This file contains tests for the suspicious shift checker.
6 6
7 package testdata 7 package testdata
8 8
9 func ShiftTest() { 9 func ShiftTest() {
10 var i8 int8 10 var i8 int8
11 _ = i8 << 7 11 _ = i8 << 7
12 » _ = (i8 + 1) << 8 // ERROR "\(i8 \+ 1\) has size 8 but is shifted by 8" 12 » _ = (i8 + 1) << 8 // ERROR "\(i8 \+ 1\) too small for shift of 8"
13 » _ = i8 << (7 + 1) // ERROR "i8 has size 8 but is shifted by 8" 13 » _ = i8 << (7 + 1) // ERROR "i8 too small for shift of 8"
14 » _ = i8 >> 8 // ERROR "i8 has size 8 but is shifted by 8" 14 » _ = i8 >> 8 // ERROR "i8 too small for shift of 8"
15 » i8 <<= 8 // ERROR "i8 has size 8 but is shifted by 8" 15 » i8 <<= 8 // ERROR "i8 too small for shift of 8"
16 » i8 >>= 8 // ERROR "i8 has size 8 but is shifted by 8" 16 » i8 >>= 8 // ERROR "i8 too small for shift of 8"
17 var i16 int16 17 var i16 int16
18 _ = i16 << 15 18 _ = i16 << 15
19 » _ = i16 << 16 // ERROR "i16 has size 16 but is shifted by 16" 19 » _ = i16 << 16 // ERROR "i16 too small for shift of 16"
20 » _ = i16 >> 16 // ERROR "i16 has size 16 but is shifted by 16" 20 » _ = i16 >> 16 // ERROR "i16 too small for shift of 16"
21 » i16 <<= 16 // ERROR "i16 has size 16 but is shifted by 16" 21 » i16 <<= 16 // ERROR "i16 too small for shift of 16"
22 » i16 >>= 16 // ERROR "i16 has size 16 but is shifted by 16" 22 » i16 >>= 16 // ERROR "i16 too small for shift of 16"
23 var i32 int32 23 var i32 int32
24 _ = i32 << 31 24 _ = i32 << 31
25 » _ = i32 << 32 // ERROR "i32 has size 32 but is shifted by 32" 25 » _ = i32 << 32 // ERROR "i32 too small for shift of 32"
26 » _ = i32 >> 32 // ERROR "i32 has size 32 but is shifted by 32" 26 » _ = i32 >> 32 // ERROR "i32 too small for shift of 32"
27 » i32 <<= 32 // ERROR "i32 has size 32 but is shifted by 32" 27 » i32 <<= 32 // ERROR "i32 too small for shift of 32"
28 » i32 >>= 32 // ERROR "i32 has size 32 but is shifted by 32" 28 » i32 >>= 32 // ERROR "i32 too small for shift of 32"
29 var i64 int64 29 var i64 int64
30 _ = i64 << 63 30 _ = i64 << 63
31 » _ = i64 << 64 // ERROR "i64 has size 64 but is shifted by 64" 31 » _ = i64 << 64 // ERROR "i64 too small for shift of 64"
32 » _ = i64 >> 64 // ERROR "i64 has size 64 but is shifted by 64" 32 » _ = i64 >> 64 // ERROR "i64 too small for shift of 64"
33 » i64 <<= 64 // ERROR "i64 has size 64 but is shifted by 64" 33 » i64 <<= 64 // ERROR "i64 too small for shift of 64"
34 » i64 >>= 64 // ERROR "i64 has size 64 but is shifted by 64" 34 » i64 >>= 64 // ERROR "i64 too small for shift of 64"
35 var u8 uint8 35 var u8 uint8
36 _ = u8 << 7 36 _ = u8 << 7
37 » _ = u8 << 8 // ERROR "u8 has size 8 but is shifted by 8" 37 » _ = u8 << 8 // ERROR "u8 too small for shift of 8"
38 » _ = u8 >> 8 // ERROR "u8 has size 8 but is shifted by 8" 38 » _ = u8 >> 8 // ERROR "u8 too small for shift of 8"
39 » u8 <<= 8 // ERROR "u8 has size 8 but is shifted by 8" 39 » u8 <<= 8 // ERROR "u8 too small for shift of 8"
40 » u8 >>= 8 // ERROR "u8 has size 8 but is shifted by 8" 40 » u8 >>= 8 // ERROR "u8 too small for shift of 8"
41 var u16 uint16 41 var u16 uint16
42 _ = u16 << 15 42 _ = u16 << 15
43 » _ = u16 << 16 // ERROR "u16 has size 16 but is shifted by 16" 43 » _ = u16 << 16 // ERROR "u16 too small for shift of 16"
44 » _ = u16 >> 16 // ERROR "u16 has size 16 but is shifted by 16" 44 » _ = u16 >> 16 // ERROR "u16 too small for shift of 16"
45 » u16 <<= 16 // ERROR "u16 has size 16 but is shifted by 16" 45 » u16 <<= 16 // ERROR "u16 too small for shift of 16"
46 » u16 >>= 16 // ERROR "u16 has size 16 but is shifted by 16" 46 » u16 >>= 16 // ERROR "u16 too small for shift of 16"
47 var u32 uint32 47 var u32 uint32
48 _ = u32 << 31 48 _ = u32 << 31
49 » _ = u32 << 32 // ERROR "u32 has size 32 but is shifted by 32" 49 » _ = u32 << 32 // ERROR "u32 too small for shift of 32"
50 » _ = u32 >> 32 // ERROR "u32 has size 32 but is shifted by 32" 50 » _ = u32 >> 32 // ERROR "u32 too small for shift of 32"
51 » u32 <<= 32 // ERROR "u32 has size 32 but is shifted by 32" 51 » u32 <<= 32 // ERROR "u32 too small for shift of 32"
52 » u32 >>= 32 // ERROR "u32 has size 32 but is shifted by 32" 52 » u32 >>= 32 // ERROR "u32 too small for shift of 32"
53 var u64 uint64 53 var u64 uint64
54 _ = u64 << 63 54 _ = u64 << 63
55 » _ = u64 << 64 // ERROR "u64 has size 64 but is shifted by 64" 55 » _ = u64 << 64 // ERROR "u64 too small for shift of 64"
56 » _ = u64 >> 64 // ERROR "u64 has size 64 but is shifted by 64" 56 » _ = u64 >> 64 // ERROR "u64 too small for shift of 64"
57 » u64 <<= 64 // ERROR "u64 has size 64 but is shifted by 64" 57 » u64 <<= 64 // ERROR "u64 too small for shift of 64"
58 » u64 >>= 64 // ERROR "u64 has size 64 but is shifted by 64" 58 » u64 >>= 64 // ERROR "u64 too small for shift of 64"
59 _ = u64 << u64 // Non-constant shifts should succeed. 59 _ = u64 << u64 // Non-constant shifts should succeed.
60 var i int 60 var i int
61 _ = i << 31 61 _ = i << 31
62 » _ = i << 32 // ERROR "i has size 32 but is shifted by 32" 62 » _ = i << 32 // ERROR "i might be too small for shift of 32"
63 » _ = i >> 32 // ERROR "i has size 32 but is shifted by 32" 63 » _ = i >> 32 // ERROR "i might be too small for shift of 32"
64 » i <<= 32 // ERROR "i has size 32 but is shifted by 32" 64 » i <<= 32 // ERROR "i might be too small for shift of 32"
65 » i >>= 32 // ERROR "i has size 32 but is shifted by 32" 65 » i >>= 32 // ERROR "i might be too small for shift of 32"
66 var u uint 66 var u uint
67 _ = u << 31 67 _ = u << 31
68 » _ = u << 32 // ERROR "u has size 32 but is shifted by 32" 68 » _ = u << 32 // ERROR "u might be too small for shift of 32"
69 » _ = u >> 32 // ERROR "u has size 32 but is shifted by 32" 69 » _ = u >> 32 // ERROR "u might be too small for shift of 32"
70 » u <<= 32 // ERROR "u has size 32 but is shifted by 32" 70 » u <<= 32 // ERROR "u might be too small for shift of 32"
71 » u >>= 32 // ERROR "u has size 32 but is shifted by 32" 71 » u >>= 32 // ERROR "u might be too small for shift of 32"
72 var p uintptr 72 var p uintptr
73 _ = p << 31 73 _ = p << 31
74 » _ = p << 32 // ERROR "p has size 32 but is shifted by 32" 74 » _ = p << 32 // ERROR "p might be too small for shift of 32"
75 » _ = p >> 32 // ERROR "p has size 32 but is shifted by 32" 75 » _ = p >> 32 // ERROR "p might be too small for shift of 32"
76 » p <<= 32 // ERROR "p has size 32 but is shifted by 32" 76 » p <<= 32 // ERROR "p might be too small for shift of 32"
77 » p >>= 32 // ERROR "p has size 32 but is shifted by 32" 77 » p >>= 32 // ERROR "p might be too small for shift of 32"
78 } 78 }
LEFTRIGHT

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b