Chandler Carruth | 1366392 | 2012-01-26 09:28:50 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -w -fdump-record-layouts %s 2> %t.layouts |
| 2 | // RUN: %clang_cc1 -w -fdump-record-layouts-simple %s > %t.before 2>&1 |
| 3 | // RUN: %clang_cc1 -w -DPACKED= -DALIGNED16= -fdump-record-layouts-simple -foverride-record-layout=%t.layouts %s > %t.after 2>&1 |
Douglas Gregor | 453dbcb | 2012-01-26 07:55:45 +0000 | [diff] [blame] | 4 | // RUN: diff %t.before %t.after |
| 5 | // RUN: FileCheck %s < %t.after |
| 6 | |
| 7 | // If not explicitly disabled, set PACKED to the packed attribute. |
| 8 | #ifndef PACKED |
| 9 | # define PACKED __attribute__((packed)) |
| 10 | #endif |
| 11 | |
| 12 | // If not explicitly disabled, set ALIGNED16 to 16-byte alignment. |
| 13 | #ifndef ALIGNED16 |
| 14 | # define ALIGNED16 __attribute__((aligned(16))) |
| 15 | #endif |
| 16 | |
| 17 | // CHECK: Type: struct X0 |
| 18 | struct X0 { |
| 19 | int x[6] PACKED; |
| 20 | }; |
| 21 | |
| 22 | // CHECK: Type: struct X1 |
| 23 | struct X1 { |
| 24 | char x[13]; |
| 25 | struct X0 y; |
| 26 | } PACKED; |
| 27 | |
| 28 | // CHECK: Type: struct X2 |
| 29 | struct PACKED X2 { |
| 30 | short x; |
| 31 | int y; |
| 32 | }; |
| 33 | |
| 34 | // CHECK: Type: struct X3 |
| 35 | struct X3 { |
| 36 | short x PACKED; |
| 37 | int y; |
| 38 | }; |
| 39 | |
| 40 | #pragma pack(push,2) |
| 41 | // CHECK: Type: struct X4 |
| 42 | struct X4 { |
| 43 | int x; |
| 44 | int y; |
| 45 | }; |
| 46 | #pragma pack(pop) |
| 47 | |
| 48 | // CHECK: Type: struct X5 |
| 49 | struct PACKED X5 { double a[19]; signed char b; }; |
| 50 | |
| 51 | // CHECK: Type: struct X6 |
| 52 | struct PACKED X6 { long double a; char b; }; |
| 53 | |
| 54 | // CHECK: Type: struct X7 |
Douglas Gregor | a2a5028 | 2012-01-26 17:23:00 +0000 | [diff] [blame^] | 55 | struct X7 { |
Douglas Gregor | 453dbcb | 2012-01-26 07:55:45 +0000 | [diff] [blame] | 56 | unsigned x; |
| 57 | unsigned char y; |
| 58 | } PACKED; |
| 59 | |
| 60 | // CHECK: Type: union X8 |
| 61 | union X8 { |
| 62 | struct X7 x; |
| 63 | unsigned y; |
| 64 | } PACKED; |
| 65 | |
| 66 | // CHECK: Type: struct X9 |
| 67 | struct X9 { |
| 68 | unsigned int x[2] PACKED; |
| 69 | unsigned int y; |
| 70 | unsigned int z PACKED; |
| 71 | }; |
| 72 | |
| 73 | // CHECK: Type: struct X10 |
| 74 | struct X10 { |
| 75 | unsigned int x[2] PACKED; |
| 76 | unsigned int y PACKED; |
| 77 | unsigned int z PACKED; |
| 78 | }; |
| 79 | |
| 80 | // CHECK: Type: struct X11 |
| 81 | struct PACKED X11 { |
| 82 | unsigned int x[2]; |
| 83 | unsigned int y; |
| 84 | unsigned int z; |
| 85 | }; |
| 86 | |
| 87 | // CHECK: Type: struct X12 |
| 88 | struct PACKED X12 { |
| 89 | int x : 24; |
| 90 | }; |
| 91 | |
| 92 | // CHECK: Type: struct X13 |
| 93 | struct PACKED X13 { |
| 94 | signed x : 10; |
| 95 | signed y : 10; |
| 96 | }; |
| 97 | |
| 98 | // CHECK: Type: union X14 |
| 99 | union PACKED X14 { |
| 100 | unsigned long long x : 3; |
| 101 | }; |
| 102 | |
| 103 | // CHECK: Type: struct X15 |
| 104 | struct X15 { |
| 105 | unsigned x : 16; |
| 106 | unsigned y : 28 PACKED; |
| 107 | }; |
| 108 | |
| 109 | // CHECK: Type: struct X16 |
| 110 | struct ALIGNED16 X16 { |
| 111 | int a, b, c; |
| 112 | int x : 5; |
| 113 | int y : 29; |
| 114 | }; |
| 115 | |
| 116 | void use_structs() { |
| 117 | struct X0 x0; |
| 118 | x0.x[5] = sizeof(struct X0); |
| 119 | |
| 120 | struct X1 x1; |
| 121 | x1.x[5] = sizeof(struct X1); |
| 122 | |
| 123 | struct X2 x2; |
| 124 | x2.y = sizeof(struct X2); |
| 125 | |
| 126 | struct X3 x3; |
| 127 | x3.y = sizeof(struct X3); |
| 128 | |
| 129 | struct X4 x4; |
| 130 | x4.y = sizeof(struct X4); |
| 131 | |
| 132 | struct X5 x5; |
| 133 | x5.b = sizeof(struct X5); |
| 134 | |
| 135 | struct X6 x6; |
| 136 | x6.b = sizeof(struct X6); |
| 137 | |
| 138 | struct X7 x7; |
| 139 | x7.x = sizeof(struct X7); |
Douglas Gregor | a2a5028 | 2012-01-26 17:23:00 +0000 | [diff] [blame^] | 140 | x7.y = x7.x; |
Douglas Gregor | 453dbcb | 2012-01-26 07:55:45 +0000 | [diff] [blame] | 141 | |
| 142 | union X8 x8; |
Douglas Gregor | a2a5028 | 2012-01-26 17:23:00 +0000 | [diff] [blame^] | 143 | typedef int X8array[sizeof(union X8)]; |
Douglas Gregor | 453dbcb | 2012-01-26 07:55:45 +0000 | [diff] [blame] | 144 | x8.y = sizeof(union X8); |
Douglas Gregor | a2a5028 | 2012-01-26 17:23:00 +0000 | [diff] [blame^] | 145 | x8.x.x = x8.y; |
Douglas Gregor | 453dbcb | 2012-01-26 07:55:45 +0000 | [diff] [blame] | 146 | |
| 147 | struct X9 x9; |
Douglas Gregor | a2a5028 | 2012-01-26 17:23:00 +0000 | [diff] [blame^] | 148 | typedef int X9array[sizeof(struct X9)]; |
Douglas Gregor | 453dbcb | 2012-01-26 07:55:45 +0000 | [diff] [blame] | 149 | x9.y = sizeof(struct X9); |
| 150 | |
| 151 | struct X10 x10; |
Douglas Gregor | a2a5028 | 2012-01-26 17:23:00 +0000 | [diff] [blame^] | 152 | typedef int X10array[sizeof(struct X10)]; |
Douglas Gregor | 453dbcb | 2012-01-26 07:55:45 +0000 | [diff] [blame] | 153 | x10.y = sizeof(struct X10); |
| 154 | |
| 155 | struct X11 x11; |
Douglas Gregor | a2a5028 | 2012-01-26 17:23:00 +0000 | [diff] [blame^] | 156 | typedef int X11array[sizeof(struct X11)]; |
Douglas Gregor | 453dbcb | 2012-01-26 07:55:45 +0000 | [diff] [blame] | 157 | x11.y = sizeof(struct X11); |
| 158 | |
| 159 | struct X12 x12; |
| 160 | x12.x = sizeof(struct X12); |
| 161 | |
| 162 | struct X13 x13; |
| 163 | x13.x = sizeof(struct X13); |
| 164 | |
| 165 | union X14 x14; |
| 166 | x14.x = sizeof(union X14); |
| 167 | |
| 168 | struct X15 x15; |
| 169 | x15.x = sizeof(struct X15); |
| 170 | |
| 171 | struct X16 x16; |
| 172 | x16.x = sizeof(struct X16); |
| 173 | } |