Anders Carlsson | 6a24acb | 2008-02-16 01:20:23 +0000 | [diff] [blame] | 1 | // RUN: clang %s -fsyntax-only -verify |
| 2 | |
Anders Carlsson | 5a1b0c4 | 2008-02-16 19:51:36 +0000 | [diff] [blame] | 3 | // Packed structs. |
Anders Carlsson | 6a24acb | 2008-02-16 01:20:23 +0000 | [diff] [blame] | 4 | struct s { |
| 5 | char a; |
| 6 | int b __attribute__((packed)); |
| 7 | char c; |
| 8 | int d; |
| 9 | }; |
| 10 | |
Anders Carlsson | 5a1b0c4 | 2008-02-16 19:51:36 +0000 | [diff] [blame] | 11 | extern int a1[sizeof(struct s) == 12 ? 1 : -1]; |
| 12 | extern int a2[__alignof(struct s) == 4 ? 1 : -1]; |
| 13 | |
Anders Carlsson | 6a24acb | 2008-02-16 01:20:23 +0000 | [diff] [blame] | 14 | struct __attribute__((packed)) packed_s { |
| 15 | char a; |
| 16 | int b __attribute__((packed)); |
| 17 | char c; |
| 18 | int d; |
| 19 | }; |
| 20 | |
Anders Carlsson | 5a1b0c4 | 2008-02-16 19:51:36 +0000 | [diff] [blame] | 21 | extern int b1[sizeof(struct packed_s) == 10 ? 1 : -1]; |
| 22 | extern int b2[__alignof(struct packed_s) == 1 ? 1 : -1]; |
| 23 | |
Anders Carlsson | 6a24acb | 2008-02-16 01:20:23 +0000 | [diff] [blame] | 24 | struct fas { |
| 25 | char a; |
| 26 | int b[]; |
| 27 | }; |
| 28 | |
Anders Carlsson | 5a1b0c4 | 2008-02-16 19:51:36 +0000 | [diff] [blame] | 29 | extern int c1[sizeof(struct fas) == 4 ? 1 : -1]; |
| 30 | extern int c2[__alignof(struct fas) == 4 ? 1 : -1]; |
| 31 | |
Anders Carlsson | 6a24acb | 2008-02-16 01:20:23 +0000 | [diff] [blame] | 32 | struct __attribute__((packed)) packed_fas { |
| 33 | char a; |
| 34 | int b[]; |
| 35 | }; |
| 36 | |
Anders Carlsson | 6a24acb | 2008-02-16 01:20:23 +0000 | [diff] [blame] | 37 | extern int d1[sizeof(struct packed_fas) == 1 ? 1 : -1]; |
| 38 | extern int d2[__alignof(struct packed_fas) == 1 ? 1 : -1]; |
Anders Carlsson | 5a1b0c4 | 2008-02-16 19:51:36 +0000 | [diff] [blame] | 39 | |
| 40 | // Alignment |
| 41 | |
| 42 | struct __attribute__((aligned(8))) as1 { |
| 43 | char c; |
| 44 | }; |
| 45 | |
| 46 | extern int e1[sizeof(struct as1) == 8 ? 1 : -1]; |
| 47 | extern int e2[__alignof(struct as1) == 8 ? 1 : -1]; |
| 48 | |
| 49 | struct as2 { |
| 50 | char c; |
| 51 | int __attribute__((aligned(8))) a; |
| 52 | }; |
| 53 | |
| 54 | extern int f1[sizeof(struct as2) == 16 ? 1 : -1]; |
| 55 | extern int f2[__alignof(struct as2) == 8 ? 1 : -1]; |
| 56 | |
| 57 | struct __attribute__((packed)) as3 { |
| 58 | char c; |
| 59 | int a; |
| 60 | int __attribute__((aligned(8))) b; |
| 61 | }; |
| 62 | |
| 63 | extern int g1[sizeof(struct as3) == 16 ? 1 : -1]; |
| 64 | extern int g2[__alignof(struct as3) == 8 ? 1 : -1]; |
Chris Lattner | abb5758 | 2008-05-09 05:34:49 +0000 | [diff] [blame] | 65 | |
| 66 | |
| 67 | // rdar://5921025 |
| 68 | struct packedtest { |
| 69 | int ted_likes_cheese; |
| 70 | void *args[] __attribute__((packed)); |
| 71 | }; |
Eli Friedman | 4bd998b | 2008-05-30 09:31:38 +0000 | [diff] [blame] | 72 | |
| 73 | // Packed union |
| 74 | union __attribute__((packed)) au4 {char c; int x;}; |
| 75 | extern int h1[sizeof(union au4) == 4 ? 1 : -1]; |
| 76 | extern int h2[__alignof(union au4) == 1 ? 1 : -1]; |
| 77 | |
| 78 | // Aligned union |
| 79 | union au5 {__attribute__((aligned(4))) char c;}; |
| 80 | extern int h1[sizeof(union au5) == 4 ? 1 : -1]; |
| 81 | extern int h2[__alignof(union au5) == 4 ? 1 : -1]; |
| 82 | |
| 83 | // Alignment+packed |
| 84 | struct as6 {char c; __attribute__((packed, aligned(2))) int x;}; |
| 85 | extern int i1[sizeof(struct as6) == 6 ? 1 : -1]; |
| 86 | extern int i2[__alignof(struct as6) == 2 ? 1 : -1]; |
| 87 | |
| 88 | union au6 {char c; __attribute__((packed, aligned(2))) int x;}; |
| 89 | extern int k1[sizeof(union au6) == 4 ? 1 : -1]; |
| 90 | extern int k2[__alignof(union au6) == 2 ? 1 : -1]; |
| 91 | |
Daniel Dunbar | 7d07664 | 2008-10-03 17:33:35 +0000 | [diff] [blame] | 92 | // Check postfix attributes |
| 93 | union au7 {char c; int x;} __attribute__((packed)); |
| 94 | extern int l1[sizeof(union au7) == 4 ? 1 : -1]; |
| 95 | extern int l2[__alignof(union au7) == 1 ? 1 : -1]; |
| 96 | |
| 97 | struct packed_fas2 { |
| 98 | char a; |
| 99 | int b[]; |
| 100 | } __attribute__((packed)); |
| 101 | |
| 102 | extern int m1[sizeof(struct packed_fas2) == 1 ? 1 : -1]; |
| 103 | extern int m2[__alignof(struct packed_fas2) == 1 ? 1 : -1]; |