Merge from mainline (167278:168000).
[official-gcc/graphite-test-results.git] / gcc / testsuite / go.test / test / bugs / bug260.go
blob6a6331e65b3d6c87a403cd3702f71709087fc81a
1 // $G $D/$F.go && $L $F.$A && ./$A.out || echo BUG: bug260 failed
3 // Test that structures pack densely, according to the alignment of the largest field.
5 package main
7 import (
8 "fmt"
9 "os"
10 "strconv"
13 type T1 struct { x uint8 }
14 type T2 struct { x uint16 }
15 type T4 struct { x uint32 }
17 func main() {
18 report := len(os.Args) > 1
19 status := 0
20 var b1 [10]T1
21 a0, _ := strconv.Btoui64(fmt.Sprintf("%p", &b1[0])[2:], 16)
22 a1, _ := strconv.Btoui64(fmt.Sprintf("%p", &b1[1])[2:], 16)
23 if a1 != a0 + 1 {
24 fmt.Println("FAIL")
25 if report {
26 fmt.Println("alignment should be 1, is", a1-a0)
28 status = 1
30 var b2 [10]T2
31 a0, _ = strconv.Btoui64(fmt.Sprintf("%p", &b2[0])[2:], 16)
32 a1, _ = strconv.Btoui64(fmt.Sprintf("%p", &b2[1])[2:], 16)
33 if a1 != a0 + 2 {
34 if status == 0 {
35 fmt.Println("FAIL")
36 status = 1
38 if report {
39 fmt.Println("alignment should be 2, is", a1-a0)
42 var b4 [10]T4
43 a0, _ = strconv.Btoui64(fmt.Sprintf("%p", &b4[0])[2:], 16)
44 a1, _ = strconv.Btoui64(fmt.Sprintf("%p", &b4[1])[2:], 16)
45 if a1 != a0 + 4 {
46 if status == 0 {
47 fmt.Println("FAIL")
48 status = 1
50 if report {
51 fmt.Println("alignment should be 4, is", a1-a0)
54 os.Exit(status)