checklocks: always allow calls to methods of atomic wrappers

This allows the use of wrappers such as atomic.Int32 introduced in
Go 1.19 without triggering the `unexpected call to atomic function`.
This commit is contained in:
Jarek Kowalski
2023-08-21 18:58:18 -07:00
parent a102e7e0fa
commit 1b02da0f3e
2 changed files with 12 additions and 0 deletions
+4
View File
@@ -140,6 +140,10 @@ func (pc *passContext) checkAtomicCall(inst ssa.Instruction, obj types.Object, a
}
return
}
if fn.Signature.Recv() != nil {
// always allow calls to methods of atomic wrappers such as atomic.Int32 introduced in Go 1.19
return
}
if ar == nonAtomic {
// We are *not* expecting an atomic dispatch.
if _, ok := pc.forced[pc.positionKey(inst.Pos())]; !ok {
+8
View File
@@ -27,6 +27,8 @@ type atomicStruct struct {
// +checklocksignore
ignored int32
wrapper atomic.Int32 // safe without any annotations
}
func testNormalAccess(tc *atomicStruct, v chan int32, p chan *int32) {
@@ -89,3 +91,9 @@ func testAtomicMixedInvalidAtomicWrite(tc *atomicMixedStruct, v chan int32, p ch
func testAtomicMixedInvalidWrite(tc *atomicMixedStruct, v chan int32, p chan *int32) {
tc.accessedMixed = 1 // +checklocksfail:2
}
func testAtomicWrapper(tc *atomicStruct, v chan int32) {
v <- tc.wrapper.Load()
v <- tc.wrapper.Add(33)
tc.wrapper.Store(44)
}