1 // Copyright 2019 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 atomic alignment checker.
16 func intsAlignment() {
28 atomic.AddInt64(&s.h, 9)
29 atomic.AddUint64(&s.j, 0) // want "address of non 64-bit aligned field .j passed to atomic.AddUint64"
32 func floatAlignment() {
40 atomic.LoadInt64(&s.b) // want "address of non 64-bit aligned field .b passed to atomic.LoadInt64"
41 atomic.LoadUint64(&s.e)
44 func uintptrAlignment() {
53 atomic.StoreInt64(&s.b, 0) // want "address of non 64-bit aligned field .b passed to atomic.StoreInt64"
54 atomic.StoreUint64(&s.f, 0)
57 func runeAlignment() {
64 atomic.SwapInt64(&s.b, 0) // want "address of non 64-bit aligned field .b passed to atomic.SwapInt64"
65 atomic.SwapUint64(&s.c, 0)
68 func complexAlignment() {
75 atomic.CompareAndSwapInt64(&s.b, 0, 1)
76 atomic.CompareAndSwapUint64(&s.d, 0, 1)
79 // continuer ici avec les tests
81 func channelAlignment() {
89 atomic.AddInt64(&a.b, 0) // want "address of non 64-bit aligned field .b passed to atomic.AddInt64"
90 atomic.AddUint64(&a.d, 0)
93 func arrayAlignment() {
103 atomic.LoadInt64(&a.b) // want "address of non 64-bit aligned field .b passed to atomic.LoadInt64"
104 atomic.LoadInt64(&a.c)
105 atomic.LoadUint64(&a.e) // want "address of non 64-bit aligned field .e passed to atomic.LoadUint64"
108 func anonymousFieldAlignment() {
116 atomic.StoreInt64(&f.c, 12)
117 atomic.StoreInt64(&f.d, 27)
118 atomic.StoreUint64(&f.e, 6) // want "address of non 64-bit aligned field .e passed to atomic.StoreUint64"
119 atomic.StoreUint64(&f.f, 79) // want "address of non 64-bit aligned field .f passed to atomic.StoreUint64"
128 func typedStructAlignment() {
130 atomic.SwapInt64(&b.e, 9)
131 atomic.SwapUint64(&b.f, 9) // want "address of non 64-bit aligned field .f passed to atomic.SwapUint64"
134 func aliasAlignment() {
152 atomic.CompareAndSwapInt64(&e.f, 0, 1) // want "address of non 64-bit aligned field .f passed to atomic.CompareAndSwapInt64"
153 atomic.CompareAndSwapUint64(&e.i, 1, 2)
156 func stringAlignment() {
162 atomic.AddInt64(&a.c, 10) // want "address of non 64-bit aligned field .c passed to atomic.AddInt64"
165 func sliceAlignment() {
173 atomic.LoadInt64(&s.b) // want "address of non 64-bit aligned field .b passed to atomic.LoadInt64"
174 atomic.LoadUint64(&s.d)
177 func interfaceAlignment() {
187 atomic.StoreInt64(&s.b, 9)
188 atomic.StoreInt64(&s.e, 9)
189 atomic.StoreUint64(&s.f, 9) // want "address of non 64-bit aligned field .f passed to atomic.StoreUint64"
192 func pointerAlignment() {
200 atomic.SwapInt64(&s.c, 9)
201 atomic.SwapUint64(&s.e, 9) // want "address of non 64-bit aligned field .e passed to atomic.SwapUint64"
204 // non-struct fields are already 64-bits correctly aligned per Go spec
205 func nonStructFields() {
212 atomic.CompareAndSwapInt64(a, 10, 11)
213 atomic.CompareAndSwapUint64(&b[0], 5, 23)
214 atomic.CompareAndSwapInt64(&c, -1, -15)
217 func embeddedStructFields() {
223 _ struct{ _ [2]uint16 }
227 atomic.AddInt64(&s1.a, 9) // want "address of non 64-bit aligned field .a passed to atomic.AddInt64"
228 atomic.AddUint64(&s1.b, 9) // want "address of non 64-bit aligned field .b passed to atomic.AddUint64"
229 atomic.AddInt64(&s1.c, 9)