diff options
| author | Aliaksandr Valialkin <valyala@gmail.com> | 2017-03-13 19:17:41 +0200 |
|---|---|---|
| committer | Rob Pike <r@golang.org> | 2017-04-19 20:03:37 +0000 |
| commit | 78510bd17c35932cd45f1433adb21aeaa0587767 (patch) | |
| tree | 7d05d472328cf265f671c036faa3d40c058840ad /src/sync/atomic | |
| parent | 6b0bd51c1c7f34acdc5556d88a52d9a9f3b14da5 (diff) | |
| download | go-78510bd17c35932cd45f1433adb21aeaa0587767.tar.xz | |
cmd/vet: skip unreachable "if" and "case" code in shift check.
Such dead code is legitimate when dealing with arch-specific
types (int, uint, uintptr).
The CL removes the majority of 'too small for shift' false positives
from such a code.
Change-Id: I62c5635a1d3774ab2d71d3d7056f0589f214cbe5
Reviewed-on: https://go-review.googlesource.com/38065
Run-TryBot: Rob Pike <r@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rob Pike <r@golang.org>
Diffstat (limited to 'src/sync/atomic')
| -rw-r--r-- | src/sync/atomic/atomic_test.go | 24 |
1 files changed, 12 insertions, 12 deletions
diff --git a/src/sync/atomic/atomic_test.go b/src/sync/atomic/atomic_test.go index 6d0831c3f9..17baccb468 100644 --- a/src/sync/atomic/atomic_test.go +++ b/src/sync/atomic/atomic_test.go @@ -953,16 +953,20 @@ func hammerSwapUint64(addr *uint64, count int) { } } +const arch32 = unsafe.Sizeof(uintptr(0)) == 4 + func hammerSwapUintptr64(uaddr *uint64, count int) { // only safe when uintptr is 64-bit. // not called on 32-bit systems. - addr := (*uintptr)(unsafe.Pointer(uaddr)) - seed := int(uintptr(unsafe.Pointer(&count))) - for i := 0; i < count; i++ { - new := uintptr(seed+i)<<32 | uintptr(seed+i)<<32>>32 - old := SwapUintptr(addr, new) - if old>>32 != old<<32>>32 { - panic(fmt.Sprintf("SwapUintptr is not atomic: %v", old)) + if !arch32 { + addr := (*uintptr)(unsafe.Pointer(uaddr)) + seed := int(uintptr(unsafe.Pointer(&count))) + for i := 0; i < count; i++ { + new := uintptr(seed+i)<<32 | uintptr(seed+i)<<32>>32 + old := SwapUintptr(addr, new) + if old>>32 != old<<32>>32 { + panic(fmt.Sprintf("SwapUintptr is not atomic: %v", old)) + } } } } @@ -1116,8 +1120,6 @@ func hammerStoreLoadUint64(t *testing.T, paddr unsafe.Pointer) { func hammerStoreLoadUintptr(t *testing.T, paddr unsafe.Pointer) { addr := (*uintptr)(paddr) - var test64 uint64 = 1 << 50 - arch32 := uintptr(test64) == 0 v := LoadUintptr(addr) new := v if arch32 { @@ -1144,8 +1146,6 @@ func hammerStoreLoadUintptr(t *testing.T, paddr unsafe.Pointer) { func hammerStoreLoadPointer(t *testing.T, paddr unsafe.Pointer) { addr := (*unsafe.Pointer)(paddr) - var test64 uint64 = 1 << 50 - arch32 := uintptr(test64) == 0 v := uintptr(LoadPointer(addr)) new := v if arch32 { @@ -1398,7 +1398,7 @@ func TestUnaligned64(t *testing.T) { switch runtime.GOARCH { default: - if unsafe.Sizeof(int(0)) != 4 { + if !arch32 { t.Skip("test only runs on 32-bit systems") } case "amd64p32": |
