1 // RUN: %clang_cc1 -emit-llvm -o - -triple x86_64-apple-darwin9 %s | FileCheck %s 2 // RUN: %clang_cc1 -emit-llvm -o - -triple thumbv7-apple-ios -target-abi apcs-gnu %s | FileCheck %s -check-prefix=CHECK-ARM 3 4 // rdar://8823265 5 6 // Note that we're declaring global variables with these types, 7 // triggering both Sema and IRGen struct layout. 8 9 #define ATTR __attribute__((__ms_struct__)) 10 11 struct 12 { 13 char foo; 14 long : 0; 15 char bar; 16 } ATTR t1; 17 int s1 = sizeof(t1); 18 // CHECK: @s1 = global i32 2 19 // CHECK-ARM: @s1 = global i32 2 20 21 struct 22 { 23 char foo; 24 long : 0; 25 char : 0; 26 int : 0; 27 char bar; 28 } ATTR t2; 29 int s2 = sizeof(t2); 30 // CHECK: @s2 = global i32 2 31 // CHECK-ARM: @s2 = global i32 2 32 33 struct 34 { 35 char foo; 36 long : 0; 37 char : 0; 38 int : 0; 39 char bar; 40 long : 0; 41 char : 0; 42 } ATTR t3; 43 int s3 = sizeof(t3); 44 // CHECK: @s3 = global i32 2 45 // CHECK-ARM: @s3 = global i32 2 46 47 struct 48 { 49 long : 0; 50 char bar; 51 } ATTR t4; 52 int s4 = sizeof(t4); 53 // CHECK: @s4 = global i32 1 54 // CHECK-ARM: @s4 = global i32 1 55 56 struct 57 { 58 long : 0; 59 long : 0; 60 char : 0; 61 char bar; 62 } ATTR t5; 63 int s5 = sizeof(t5); 64 // CHECK: @s5 = global i32 1 65 // CHECK-ARM: @s5 = global i32 1 66 67 struct 68 { 69 long : 0; 70 long : 0; 71 char : 0; 72 char bar; 73 } ATTR t6; 74 int s6 = sizeof(t6); 75 // CHECK: @s6 = global i32 1 76 // CHECK-ARM: @s6 = global i32 1 77 78 struct 79 { 80 char foo; 81 long : 0; 82 int : 0; 83 char bar; 84 char bar1; 85 long : 0; 86 char bar2; 87 char bar3; 88 char : 0; 89 char bar4; 90 char bar5; 91 char : 0; 92 char bar6; 93 char bar7; 94 } ATTR t7; 95 int s7 = sizeof(t7); 96 // CHECK: @s7 = global i32 9 97 // CHECK-ARM: @s7 = global i32 9 98 99 struct 100 { 101 long : 0; 102 long : 0; 103 char : 0; 104 } ATTR t8; 105 int s8 = sizeof(t8); 106 // CHECK: @s8 = global i32 0 107 // CHECK-ARM: @s8 = global i32 0 108 109 struct 110 { 111 char foo; 112 long : 0; 113 int : 0; 114 char bar; 115 char bar1; 116 long : 0; 117 char bar2; 118 char bar3; 119 char : 0; 120 char bar4; 121 char bar5; 122 char : 0; 123 char bar6; 124 char bar7; 125 int i1; 126 char : 0; 127 long : 0; 128 char :4; 129 char bar8; 130 char : 0; 131 char bar9; 132 char bar10; 133 int i2; 134 char : 0; 135 long : 0; 136 char :4; 137 } ATTR t9; 138 int s9 = sizeof(t9); 139 // CHECK: @s9 = global i32 28 140 // CHECK-ARM: @s9 = global i32 28 141 142 struct 143 { 144 char foo: 8; 145 long : 0; 146 char bar; 147 } ATTR t10; 148 int s10 = sizeof(t10); 149 // CHECK: @s10 = global i32 16 150 // CHECK-ARM: @s10 = global i32 8 151 152 // rdar://16041826 - ensure that ms_structs work correctly on a 153 // !useBitFieldTypeAlignment() target 154 struct { 155 unsigned int a : 31; 156 unsigned int b : 2; 157 unsigned int c; 158 } ATTR t11; 159 int s11 = sizeof(t11); 160 // CHECK: @s11 = global i32 12 161 // CHECK-ARM: @s11 = global i32 12 162 163 struct { 164 unsigned char a : 3; 165 unsigned char b : 4; 166 unsigned short c : 6; 167 } ATTR t12; 168 int s12 = sizeof(t12); 169 // CHECK: @s12 = global i32 4 170 // CHECK-ARM: @s12 = global i32 4 171 172 struct { 173 unsigned char a : 3; 174 unsigned char b : 4; 175 __attribute__((packed)) unsigned short c : 6; 176 } ATTR t13; 177 int s13 = sizeof(t13); 178 // CHECK: @s13 = global i32 4 179 // CHECK-ARM: @s13 = global i32 4 180