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