brintos

brintos / llvm-project-archived public Read only

0
0
Text · 5.3 KiB · d6d0724 Raw
177 lines · c
1// RUN: %clang_cc1 %s -fsyntax-only -verify2// RUN: %clang_cc1 %s -fsyntax-only -triple=x86_64-windows-coff -verify3// RUN: %clang_cc1 %s -fsyntax-only -triple=x86_64-scei-ps4 -verify4// RUN: %clang_cc1 %s -fsyntax-only -triple=x86_64-sie-ps5 -verify5 6// Packed structs.7struct s {8    char a;9    int b  __attribute__((packed));10    char c;11    int d;12};13 14extern int a1[sizeof(struct s) == 12 ? 1 : -1];15extern int a2[__alignof(struct s) == 4 ? 1 : -1];16 17struct __attribute__((packed)) packed_s {18    char a;19    int b  __attribute__((packed));20    char c;21    int d;22};23 24extern int b1[sizeof(struct packed_s) == 10 ? 1 : -1];25extern int b2[__alignof(struct packed_s) == 1 ? 1 : -1];26 27struct fas {28    char a;29    int b[];30};31 32extern int c1[sizeof(struct fas) == 4 ? 1 : -1];33extern int c2[__alignof(struct fas) == 4 ? 1 : -1];34 35struct __attribute__((packed)) packed_fas {36    char a;37    int b[];38};39 40extern int d1[sizeof(struct packed_fas) == 1 ? 1 : -1];41extern int d2[__alignof(struct packed_fas) == 1 ? 1 : -1];42 43struct packed_after_fas {44    char a;45    int b[];46} __attribute__((packed));47 48extern int d1_2[sizeof(struct packed_after_fas) == 1 ? 1 : -1];49extern int d2_2[__alignof(struct packed_after_fas) == 1 ? 1 : -1];50 51// Alignment52 53struct __attribute__((aligned(8))) as1 {54    char c;55};56 57extern int e1[sizeof(struct as1) == 8 ? 1 : -1];58extern int e2[__alignof(struct as1) == 8 ? 1 : -1];59 60struct __attribute__((aligned)) as1_2 {61    char c;62};63#if ( defined(__s390x__) || ( defined (__ARM_32BIT_STATE) && ! defined(__ANDROID__) ) )64extern int e1_2[sizeof(struct as1_2) == 8 ? 1 : -1];65extern int e2_2[__alignof(struct as1_2) == 8 ? 1 : -1];66#else67extern int e1_2[sizeof(struct as1_2) == 16 ? 1 : -1];68extern int e2_2[__alignof(struct as1_2) == 16 ? 1 : -1];69#endif70 71struct as2 {72    char c;73    int __attribute__((aligned(8))) a;74};75 76extern int f1[sizeof(struct as2) == 16 ? 1 : -1];77extern int f2[__alignof(struct as2) == 8 ? 1 : -1];78 79struct __attribute__((packed)) as3 {80    char c;81    int a;82    int __attribute__((aligned(8))) b;83};84 85extern int g1[sizeof(struct as3) == 16 ? 1 : -1];86extern int g2[__alignof(struct as3) == 8 ? 1 : -1];87 88 89struct packedtest {90  int ted_likes_cheese;91  void *args[] __attribute__((packed));92};93 94// Packed union95union __attribute__((packed)) au4 {char c; int x;};96extern int h1[sizeof(union au4) == 4 ? 1 : -1];97extern int h2[__alignof(union au4) == 1 ? 1 : -1];98 99// Aligned union100union au5 {__attribute__((aligned(4))) char c;};101extern int h1[sizeof(union au5) == 4 ? 1 : -1];102extern int h2[__alignof(union au5) == 4 ? 1 : -1];103 104// Alignment+packed105struct as6 {char c; __attribute__((packed, aligned(2))) int x;};106extern int i1[sizeof(struct as6) == 6 ? 1 : -1];107extern int i2[__alignof(struct as6) == 2 ? 1 : -1];108 109union au6 {char c; __attribute__((packed, aligned(2))) int x;};110extern int k1[sizeof(union au6) == 4 ? 1 : -1];111extern int k2[__alignof(union au6) == 2 ? 1 : -1];112 113// Check postfix attributes114union au7 {char c; int x;} __attribute__((packed));115extern int l1[sizeof(union au7) == 4 ? 1 : -1];116extern int l2[__alignof(union au7) == 1 ? 1 : -1];117 118struct packed_fas2 {119    char a;120    int b[];121} __attribute__((packed));122 123extern int m1[sizeof(struct packed_fas2) == 1 ? 1 : -1];124extern int m2[__alignof(struct packed_fas2) == 1 ? 1 : -1];125 126// Attribute aligned can round down typedefs.  PR9253127typedef long long  __attribute__((aligned(1))) nt;128 129struct nS {130  char buf_nr;131  nt start_lba;132};133 134#if defined(_WIN32) && !defined(__declspec) // _MSC_VER is unavailable in cc1.135// Alignment doesn't affect packing in MS mode.136extern int n1[sizeof(struct nS) == 16 ? 1 : -1];137extern int n2[__alignof(struct nS) == 8 ? 1 : -1];138#else139extern int n1[sizeof(struct nS) == 9 ? 1 : -1];140extern int n2[__alignof(struct nS) == 1 ? 1 : -1];141#endif142 143// Packed attribute shouldn't be ignored for bit-field of char types.144// Note from GCC reference manual: The 4.1, 4.2 and 4.3 series of GCC ignore145// the packed attribute on bit-fields of type char. This has been fixed in146// GCC 4.4 but the change can lead to differences in the structure layout.147// See the documentation of -Wpacked-bitfield-compat for more information.148struct packed_chars {149  char a : 8, b : 8, c : 8, d : 4;150#ifdef __SCE__151  // Test for pre-r254596 clang behavior on the PS4/PS5 targets, which must152  // maintain ABI backwards compatibility.153  char e : 8 __attribute__((packed));154  // expected-warning@-1 {{'packed' attribute ignored for field of type 'char'}}155#else156  char e : 8 __attribute__((packed));157  // expected-warning@-1 {{'packed' attribute was ignored on bit-fields with single-byte alignment in older versions of GCC and Clang}}158#endif159  char f : 4, g : 8, h : 8, i : 8;160};161 162#if (defined(_WIN32) || defined(__SCE__)) && !defined(__declspec) // _MSC_VER is unavailable in cc1.163// On Windows clang uses MSVC compatible layout in this case.164//165// Additionally, test for pre-r254596 clang behavior on the PS4/PS5 targets.166// They must maintain ABI backwards compatibility.167extern int o1[sizeof(struct packed_chars) == 9 ? 1 : -1];168extern int o2[__alignof(struct packed_chars) == 1 ? 1 : -1];169#elif defined(_AIX)170// On AIX, char bitfields have the same alignment as unsigned int.171extern int o1[sizeof(struct packed_chars) == 8 ? 1 : -1];172extern int o2[__alignof(struct packed_chars) == 4 ? 1 : -1];173#else174extern int o1[sizeof(struct packed_chars) == 8 ? 1 : -1];175extern int o2[__alignof(struct packed_chars) == 1 ? 1 : -1];176#endif177