diff options
author | R?my Oudompheng <oudomphe@phare.normalesup.org> | 2013-01-18 22:40:32 +0100 |
---|---|---|
committer | R?my Oudompheng <oudomphe@phare.normalesup.org> | 2013-01-18 22:40:32 +0100 |
commit | a732cfcf2e3fd785549389216ac5db8d4b4691b3 (patch) | |
tree | fa5fd581c9acb6761998bf54d40b57ea6ac6fcbc /test | |
parent | 6512faf1d64c20bcd08570a074800564747a895c (diff) | |
download | go-a732cfcf2e3fd785549389216ac5db8d4b4691b3.tar.gz |
cmd/gc: fix handling of struct padding in hash/eq.
The test case of issue 4585 was not passing due to
miscalculation of memequal args, and the previous fix
does not handle padding at the end of a struct.
Handling of padding at end of structs also fixes the case
of [n]T where T is such a padded struct.
Fixes issue 4585.
(again)
R=golang-dev, rsc
CC=golang-dev
https://codereview.appspot.com/7133059
Diffstat (limited to 'test')
-rw-r--r-- | test/fixedbugs/issue4585.go | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/test/fixedbugs/issue4585.go b/test/fixedbugs/issue4585.go index 558bd1e10..ad1242d1e 100644 --- a/test/fixedbugs/issue4585.go +++ b/test/fixedbugs/issue4585.go @@ -32,6 +32,20 @@ type USmall struct { A, _, B int32 } +// V has padding but not on the first field. +type V struct { + A1, A2, A3 int32 + B int16 + C int32 +} + +// W has padding at the end. +type W struct { + A1, A2, A3 int32 + B int32 + C int8 +} + func test1() { var a, b U m := make(map[U]int) @@ -84,8 +98,54 @@ func test3() { } } +func test4() { + var a, b V + m := make(map[V]int) + + copy((*[20]byte)(unsafe.Pointer(&a))[:], "Hello World, Gopher!") + a.A1, a.A2, a.A3, a.B, a.C = 1, 2, 3, 4, 5 + b.A1, b.A2, b.A3, b.B, b.C = 1, 2, 3, 4, 5 + + if a != b { + panic("broken equality: a != b") + } + + m[a] = 1 + m[b] = 2 + if len(m) == 2 { + panic("broken hash: len(m) == 2") + } + if m[a] != 2 { + panic("m[a] != 2") + } +} + +func test5() { + var a, b W + m := make(map[W]int) + + copy((*[20]byte)(unsafe.Pointer(&a))[:], "Hello World, Gopher!") + a.A1, a.A2, a.A3, a.B, a.C = 1, 2, 3, 4, 5 + b.A1, b.A2, b.A3, b.B, b.C = 1, 2, 3, 4, 5 + + if a != b { + panic("broken equality: a != b") + } + + m[a] = 1 + m[b] = 2 + if len(m) == 2 { + panic("broken hash: len(m) == 2") + } + if m[a] != 2 { + panic("m[a] != 2") + } +} + func main() { test1() test2() test3() + test4() + test5() } |