Skip to content

Commit d092608

Browse files
committed
Align Group.Stats properly for 32-bit platforms.
Fixes golang/go#18334
1 parent a6b377e commit d092608

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

groupcache.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,8 @@ type Group struct {
166166
// concurrent callers.
167167
loadGroup flightGroup
168168

169+
_ int32 // force Stats to be 8-byte aligned on 32-bit platforms
170+
169171
// Stats are statistics on the group.
170172
Stats Stats
171173
}

groupcache_test.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import (
2727
"sync"
2828
"testing"
2929
"time"
30+
"unsafe"
3031

3132
"github.com/golang/protobuf/proto"
3233

@@ -443,5 +444,13 @@ func TestNoDedup(t *testing.T) {
443444
}
444445
}
445446

447+
func TestGroupStatsAlignment(t *testing.T) {
448+
var g Group
449+
off := unsafe.Offsetof(g.Stats)
450+
if off%8 != 0 {
451+
t.Fatal("Stats structure is not 8-byte aligned.")
452+
}
453+
}
454+
446455
// TODO(bradfitz): port the Google-internal full integration test into here,
447456
// using HTTP requests instead of our RPC system.

0 commit comments

Comments
 (0)