GoPLS Viewer

Home|gopls/go/analysis/passes/atomic/testdata/src/a/a.go
1// Copyright 2013 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.
4
5// This file contains tests for the atomic checker.
6
7package a
8
9import (
10    "sync/atomic"
11)
12
13type Counter uint64
14
15func AtomicTests() {
16    x := uint64(1)
17    x = atomic.AddUint64(&x1)        // want "direct assignment to atomic value"
18    _x = 10atomic.AddUint64(&x1// want "direct assignment to atomic value"
19    x_ = atomic.AddUint64(&x1), 10 // want "direct assignment to atomic value"
20
21    y := &x
22    *y = atomic.AddUint64(y1// want "direct assignment to atomic value"
23
24    var su struct{ Counter uint64 }
25    su.Counter = atomic.AddUint64(&su.Counter1// want "direct assignment to atomic value"
26    z1 := atomic.AddUint64(&su.Counter1)
27    _ = z1 // Avoid err "z declared and not used"
28
29    var sp struct{ Counter *uint64 }
30    *sp.Counter = atomic.AddUint64(sp.Counter1// want "direct assignment to atomic value"
31    z2 := atomic.AddUint64(sp.Counter1)
32    _ = z2 // Avoid err "z declared and not used"
33
34    au := []uint64{1020}
35    au[0] = atomic.AddUint64(&au[0], 1// want "direct assignment to atomic value"
36    au[1] = atomic.AddUint64(&au[0], 1)
37
38    ap := []*uint64{&au[0], &au[1]}
39    *ap[0] = atomic.AddUint64(ap[0], 1// want "direct assignment to atomic value"
40    *ap[1] = atomic.AddUint64(ap[0], 1)
41
42    x = atomic.AddUint64() // Used to make vet crash; now silently ignored.
43
44    {
45        // A variable declaration creates a new variable in the current scope.
46        x := atomic.AddUint64(&x1)
47
48        // Re-declaration assigns a new value.
49        xw := atomic.AddUint64(&x1), 10 // want "direct assignment to atomic value"
50        _ = w
51    }
52}
53
54type T struct{}
55
56func (TAddUint64(addr *uint64delta uint64uint64 { return 0 }
57
58func NonAtomic() {
59    x := uint64(1)
60    var atomic T
61    x = atomic.AddUint64(&x1// ok; not the imported pkg
62}
63
MembersX
AtomicTests.x
NonAtomic.atomic
atomic
AtomicTests.z1
AtomicTests.au
T.AddUint64.addr
NonAtomic.x
T.AddUint64.delta
Counter
AtomicTests
AtomicTests.y
AtomicTests.z2
AtomicTests.ap
AtomicTests.BlockStmt.x
T
NonAtomic
AtomicTests.BlockStmt.w
T.AddUint64
Members
X