1 #include <stdio.h>
2
3
4 void
check_alignment(void * addr,unsigned int align)5 check_alignment(void *addr, unsigned int align) {
6 if ((unsigned long)addr % align) {
7 puts("BUG");
8 } else {
9 puts("OK");
10 }
11 }
12
13 /*
14 * 07/11/13: This test came up on SPARC; Nested scopes yielded problems because
15 * alignment wasn't done properly across scope boundaries!
16 */
17 int
main()18 main() {
19 int three = 3;
20 char x = 5;
21 {
22 int y = 35;
23 {
24 long z = 666;
25 char buf[three];
26 long f;
27 *buf = 1;
28 printf("%d, %d, %ld\n", x, y, z);
29 check_alignment(&x, __alignof x);
30 check_alignment(&y, __alignof y);
31 check_alignment(&z, __alignof z);
32 check_alignment(&f, __alignof f);
33 }
34 }
35
36 {
37 static int sx = 52;
38 {
39 int sy = 353;
40 {
41 static char buf[3];
42 static long sz = 35221;
43 static long f;
44 printf("%d, %d, %ld\n", sx, sy, sz);
45 *buf = 1;
46 check_alignment(&sx, __alignof sx);
47 check_alignment(&sy, __alignof sy);
48 check_alignment(&sz, __alignof sz);
49 check_alignment(&sz, __alignof f);
50 }
51 }
52 }
53 return 0;
54 }
55
56