Skip to content

Commit 1e5e980

Browse files
committed
govet: add 32bit variant of fieldalignment test
1 parent 9e832c9 commit 1e5e980

File tree

3 files changed

+63
-0
lines changed

3 files changed

+63
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
//go:build 386 || arm || mips || mipsle
2+
//golangcitest:args -Egovet
3+
//golangcitest:config_path testdata/govet_fieldalignment.yml
4+
package testdata
5+
6+
type gvfaGood struct {
7+
y int32
8+
x byte
9+
z byte
10+
}
11+
12+
type gvfaBad struct { // want "struct of size 12 could be 8"
13+
x byte
14+
y int32
15+
z byte
16+
}
17+
18+
type gvfaPointerGood struct {
19+
P *int
20+
buf [1000]uintptr
21+
}
22+
23+
type gvfaPointerBad struct { // want "struct with 4004 pointer bytes could be 4"
24+
buf [1000]uintptr
25+
P *int
26+
}
27+
28+
type gvfaPointerSorta struct {
29+
a struct {
30+
p *int
31+
q uintptr
32+
}
33+
b struct {
34+
p *int
35+
q [2]uintptr
36+
}
37+
}
38+
39+
type gvfaPointerSortaBad struct { // want "struct with 16 pointer bytes could be 12"
40+
a struct {
41+
p *int
42+
q [2]uintptr
43+
}
44+
b struct {
45+
p *int
46+
q uintptr
47+
}
48+
}
49+
50+
type gvfaZeroGood struct {
51+
a [0]byte
52+
b uint32
53+
}
54+
55+
type gvfaZeroBad struct { // want "struct of size 8 could be 4"
56+
a uint32
57+
b [0]byte
58+
}

pkg/golinters/govet/testdata/govet_fieldalignment.go pkg/golinters/govet/testdata/govet_fieldalignment_64.go

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
//go:build !(386 || arm || mips || mipsle)
12
//golangcitest:args -Egovet
23
//golangcitest:config_path testdata/govet_fieldalignment.yml
34
package testdata

test/testshared/directives.go

+4
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,10 @@ func evaluateBuildTags(tb testing.TB, line string) bool {
136136
return true
137137
}
138138

139+
if tag == runtime.GOARCH {
140+
return true
141+
}
142+
139143
if buildTagGoVersion(tag) {
140144
return true
141145
}

0 commit comments

Comments
 (0)