brintos

brintos / llvm-project-archived public Read only

0
0
Text · 5.3 KiB · c0f90f7 Raw
197 lines · cpp
1 2// RUN: %clang_cc1 -fsyntax-only -Wms-bitfield-padding -verify -triple armv8 -std=c++23 %s3// RUN: %clang_cc1 -fsyntax-only -DMS_BITFIELDS -mms-bitfields -verify=msbitfields -triple armv8-apple-macos10.15 -std=c++23 %s4 5// msbitfields-no-diagnostics6 7enum Enum1 { Enum1_A, Enum1_B };8enum Enum2 { Enum2_A, Enum2_B };9 10enum class EnumU32_1 : unsigned { A, B };11enum class EnumU32_2 : unsigned { A, B };12enum class EnumU64 : unsigned long long { A, B };13enum class EnumI32 : int { A, B };14enum class EnumU8 : unsigned char { A, B };15enum class EnumI8 : char { A, B };16enum class EnumU16 : unsigned short { A, B };17enum class EnumI16 : short { A, B };18 19struct A {20  unsigned int a : 15;21  unsigned int b : 15;22};23static_assert(sizeof(A) == 4);24 25struct B {26  unsigned int a : 15;27           int b : 15;28};29static_assert(sizeof(B) == 4);30 31struct C {32  unsigned int a : 15;33           int b : 15;34};35static_assert(sizeof(C) == 4);36 37struct D {38  Enum1 a : 15;39  Enum1 b : 15;40};41static_assert(sizeof(D) == 4);42 43struct E {44  Enum1 a : 15;45  Enum2 b : 15;46};47static_assert(sizeof(E) == 4);48 49struct F {50  EnumU32_1 a : 15;51  EnumU32_2 b : 15;52};53static_assert(sizeof(F) == 4);54 55struct G {56  EnumU32_1 a : 15;57  EnumU64 b : 15;58  // expected-warning@-1 {{bit-field 'b' of type 'EnumU64' has a different storage size than the preceding bit-field (8 vs 4 bytes) and will not be packed under the Microsoft ABI}}59  // expected-note@-3 {{preceding bit-field 'a' declared here with type 'EnumU32_1'}}60};61 62#ifdef MS_BITFIELDS63  static_assert(sizeof(G) == 16);64#else65  static_assert(sizeof(G) == 8);66#endif67 68struct H {69  EnumU32_1 a : 10;70  EnumI32 b : 10;71  EnumU32_1 c : 10;72};73static_assert(sizeof(H) == 4);74 75struct I {76  EnumU8 a : 3;77  EnumI8 b : 5;78  EnumU32_1 c : 10;79  // expected-warning@-1 {{bit-field 'c' of type 'EnumU32_1' has a different storage size than the preceding bit-field (4 vs 1 bytes) and will not be packed under the Microsoft ABI}}80  // expected-note@-3 {{preceding bit-field 'b' declared here with type 'EnumI8'}}81};82#ifdef MS_BITFIELDS83static_assert(sizeof(I) == 8);84#else85static_assert(sizeof(I) == 4);86#endif87 88struct J {89  EnumU8 : 0;90  EnumU8 b : 4;91};92static_assert(sizeof(J) == 1);93 94struct K {95  EnumU8 a : 4;96  EnumU8 : 0;97};98static_assert(sizeof(K) == 1);99 100struct L {101  EnumU32_1 a : 10;102  EnumU32_2 b : 10;103  EnumU32_1 c : 10;104};105 106static_assert(sizeof(L) == 4);107 108struct M {109  EnumU32_1 a : 10;110  EnumI32 b : 10;111  EnumU32_1 c : 10;112};113 114static_assert(sizeof(M) == 4);115 116struct N {117  EnumU32_1 a : 10;118  EnumU64 b : 10;119  // expected-warning@-1 {{bit-field 'b' of type 'EnumU64' has a different storage size than the preceding bit-field (8 vs 4 bytes) and will not be packed under the Microsoft ABI}}120  // expected-note@-3 {{preceding bit-field 'a' declared here with type 'EnumU32_1'}}121  EnumU32_1 c : 10;122  // expected-warning@-1 {{bit-field 'c' of type 'EnumU32_1' has a different storage size than the preceding bit-field (4 vs 8 bytes) and will not be packed under the Microsoft ABI}}123  // expected-note@-5 {{preceding bit-field 'b' declared here with type 'EnumU64'}}124};125 126#ifdef MS_BITFIELDS127static_assert(sizeof(N) == 24);128#else129static_assert(sizeof(N) == 8);130#endif131 132struct O {133  EnumU16 a : 10;134  EnumU32_1 b : 10;135  // expected-warning@-1 {{bit-field 'b' of type 'EnumU32_1' has a different storage size than the preceding bit-field (4 vs 2 bytes) and will not be packed under the Microsoft ABI}}136  // expected-note@-3 {{preceding bit-field 'a' declared here with type 'EnumU16'}}137};138#ifdef MS_BITFIELDS139static_assert(sizeof(O) == 8);140#else141static_assert(sizeof(O) == 4);142#endif143 144struct P {145  EnumU32_1 a : 10;146  EnumU16 b : 10;147  // expected-warning@-1 {{bit-field 'b' of type 'EnumU16' has a different storage size than the preceding bit-field (2 vs 4 bytes) and will not be packed under the Microsoft ABI}}148  // expected-note@-3 {{preceding bit-field 'a' declared here with type 'EnumU32_1'}}149};150#ifdef MS_BITFIELDS151static_assert(sizeof(P) == 8);152#else153static_assert(sizeof(P) == 4);154#endif155 156struct Q {157  EnumU8 a : 6;158  EnumU16 b : 6;159  // expected-warning@-1 {{bit-field 'b' of type 'EnumU16' has a different storage size than the preceding bit-field (2 vs 1 bytes) and will not be packed under the Microsoft ABI}}160  // expected-note@-3 {{preceding bit-field 'a' declared here with type 'EnumU8'}}161};162#ifdef MS_BITFIELDS163static_assert(sizeof(Q) == 4);164#else165static_assert(sizeof(Q) == 2);166#endif167 168struct R {169  EnumU16 a : 9;170  EnumU16 b : 9;171  EnumU8 c : 6;172  // expected-warning@-1 {{bit-field 'c' of type 'EnumU8' has a different storage size than the preceding bit-field (1 vs 2 bytes) and will not be packed under the Microsoft ABI}}173  // expected-note@-3 {{preceding bit-field 'b' declared here with type 'EnumU16'}}174};175 176#ifdef MS_BITFIELDS177static_assert(sizeof(R) == 6);178#else179static_assert(sizeof(R) == 4);180#endif181 182struct S {183  char a : 4;184  char b : 4;185  char c : 4;186  char d : 4;187  short x : 7;188  // expected-warning@-1 {{bit-field 'x' of type 'short' has a different storage size than the preceding bit-field (2 vs 1 bytes) and will not be packed under the Microsoft ABI}}189  // expected-note@-3 {{preceding bit-field 'd' declared here with type 'char'}}190  // This is a false positive. Reporting this correctly requires duplicating the record layout process191  // in target and MS layout modes, and it's also unclear if that's the correct choice for users of192  // this diagnostic.193  short y : 9;194};195 196static_assert(sizeof(S) == 4);197