In Go 1.22.2 there is a test in the runtime/internal/atomic which looks like below:
func TestAnd64(t *testing.T) {
// Basic sanity check.
x := uint64(0xffffffffffffffff)
for i := uint64(0); i < 64; i++ {
old := x
v := atomic.And64(&x, ^(1 << i))
if r := uint64(0xffffffffffffffff) << (i + 1); x != r || v != old {
t.Fatalf("clearing bit %#x: want %#x, got new %#x and old %#v", uint64(1<<i), r, x, v)
}
}
// ...
}
It pass on linux/arm but fails on my linux/thumb port because of the lack of 64-bit alignment. In both cases the x doesn't escape and stays on the stack, but in case of arm it seems always to be 64-bit aligned.
I can broke this test by adding another local uint32 variable after or before x.
Is there something that guarantees that the x is always 64-bit aligned or is it a bug, that unfortunately doesn't
reveal itself in this test?
According to my findings the max. alignment guaranteed on the stack is RegSize but maybe I missed something.