brintos

brintos / llvm-project-archived public Read only

0
0
Text · 11.6 KiB · 4680ff4 Raw
517 lines · c
1// RUN: %clang_cc1 %s -triple=armv7-none-none-eabi -verify -Wunaligned-access -emit-llvm -o %t2// REQUIRES: arm-registered-target3//4// This test suite tests the warning triggered by the -Wunaligned-access option.5// The warning occurs when a struct or other type of record contains a field6// that is itself a record. The outer record must be a packed structure, while7// while the inner record must be unpacked. This is the fundamental condition8// for the warning to be triggered. Some of these tests may have three layers.9//10// The command line option -fsyntax-only is not used as Clang needs to be11// forced to layout the structs used in this test.12// The triple in the command line above is used for the assumptions about13// size and alignment of types.14 15// Set 116struct T1 {17  char a;18  int b;19};20 21struct __attribute__((packed)) U1 {22  char a;23  struct T1 b; // expected-warning {{field b within 'struct U1' is less aligned than 'struct T1' and is usually due to 'struct U1' being packed, which can lead to unaligned accesses}}24  int c;25};26 27struct __attribute__((packed)) U2 {28  char a;29  struct T1 b __attribute__((aligned(2))); // expected-warning {{field b within 'struct U2' is less aligned than 'struct T1' and is usually due to 'struct U2' being packed, which can lead to unaligned accesses}}30  int c;31};32 33struct __attribute__((packed)) U3 {34  char a;35  struct T1 b __attribute__((aligned(4)));36  int c;37};38 39struct __attribute__((aligned(2))) U4 {40  char a;41  struct T1 b;42  int c;43};44 45struct U5 {46  char a;47  struct T1 b;48  int c;49};50 51struct U6 {52  char a;53  int b;54  struct T1 c __attribute__((aligned(2)));55};56 57struct __attribute__((packed)) U7 {58  short a;59  short b;60  char c;61  struct T1 d; // expected-warning {{field d within 'struct U7' is less aligned than 'struct T1' and is usually due to 'struct U7' being packed, which can lead to unaligned accesses}}62};63 64struct U8 {65  short a;66  short b;67  char c;68  struct T1 d;69};70 71struct __attribute__((packed)) U9 {72  short a;73  short b;74  char c;75  struct T1 d __attribute__((aligned(4)));76};77 78struct __attribute__((packed)) U10 {79  short a;80  short b;81  char c;82  struct T1 d __attribute__((aligned(2))); // expected-warning {{field d within 'struct U10' is less aligned than 'struct T1' and is usually due to 'struct U10' being packed, which can lead to unaligned accesses}}83};84 85struct __attribute__((aligned(2))) U11 {86  short a;87  short b;88  char c;89  struct T1 d;90};91 92// Set 293#pragma pack(push, 1)94 95struct U12 {96  char a;97  struct T1 b; // expected-warning {{field b within 'struct U12' is less aligned than 'struct T1' and is usually due to 'struct U12' being packed, which can lead to unaligned accesses}}98  int c;99};100 101struct __attribute__((packed)) U13 {102  char a;103  struct T1 b; // expected-warning {{field b within 'struct U13' is less aligned than 'struct T1' and is usually due to 'struct U13' being packed, which can lead to unaligned accesses}}104  int c;105};106 107struct __attribute__((packed)) U14 {108  char a;109  struct T1 b __attribute__((aligned(4))); // expected-warning {{field b within 'struct U14' is less aligned than 'struct T1' and is usually due to 'struct U14' being packed, which can lead to unaligned accesses}}110  int c;111};112 113struct __attribute__((aligned(2))) U15 {114  char a;115  struct T1 b; // expected-warning {{field b within 'struct U15' is less aligned than 'struct T1' and is usually due to 'struct U15' being packed, which can lead to unaligned accesses}}116  int c;117};118 119struct U16 {120  char a;121  char b;122  short c;123  struct T1 d;124};125 126struct U17 {127  char a;128  char b;129  short c;130  struct T1 d __attribute__((aligned(4)));131};132 133struct __attribute__((packed)) U18 {134  char a;135  short b;136  struct T1 c __attribute__((aligned(4))); // expected-warning {{field c within 'struct U18' is less aligned than 'struct T1' and is usually due to 'struct U18' being packed, which can lead to unaligned accesses}}137};138 139struct __attribute__((aligned(4))) U19 {140  char a;141  struct T1 b; // expected-warning {{field b within 'struct U19' is less aligned than 'struct T1' and is usually due to 'struct U19' being packed, which can lead to unaligned accesses}}142  int c;143};144 145struct __attribute__((aligned(4))) U20 {146  char a[4];147  struct T1 b;148  int c;149};150 151struct U21 {152  char a;153  short c;154  struct T1 d; // expected-warning {{field d within 'struct U21' is less aligned than 'struct T1' and is usually due to 'struct U21' being packed, which can lead to unaligned accesses}}155};156 157struct U22 {158  char a;159  short c;160  struct T1 d __attribute__((aligned(4))); // expected-warning {{field d within 'struct U22' is less aligned than 'struct T1' and is usually due to 'struct U22' being packed, which can lead to unaligned accesses}}161};162 163#pragma pack(pop)164 165// Set 3166#pragma pack(push, 2)167 168struct __attribute__((packed)) U23 {169  char a;170  struct T1 b; // expected-warning {{field b within 'struct U23' is less aligned than 'struct T1' and is usually due to 'struct U23' being packed, which can lead to unaligned accesses}}171  int c;172};173 174struct U24 {175  char a;176  struct T1 b; // expected-warning {{field b within 'struct U24' is less aligned than 'struct T1' and is usually due to 'struct U24' being packed, which can lead to unaligned accesses}}177  int c;178};179 180struct U25 {181  char a;182  char b;183  short c;184  struct T1 d;185};186 187struct U26 {188  char a;189  char b;190  short c;191  struct T1 d;192};193 194#pragma pack(pop)195 196// Set 4197 198struct __attribute__((packed)) T2 {199  char a;200  struct T1 b; // expected-warning {{field b within 'struct T2' is less aligned than 'struct T1' and is usually due to 'struct T2' being packed, which can lead to unaligned accesses}}201};202 203struct T3 {204  char a;205  struct T1 b;206};207 208struct __attribute__((packed)) U27 {209  char a;210  struct T2 b;211  int c;212};213 214struct U28 {215  char a;216  char _p[2];217  struct T2 b;218  int c;219};220 221struct U29 {222  char a;223  struct T3 b;224  int c;225};226 227struct __attribute__((packed)) U30 {228  char a;229  struct T3 b; // expected-warning {{field b within 'struct U30' is less aligned than 'struct T3' and is usually due to 'struct U30' being packed, which can lead to unaligned accesses}}230  int c;231};232 233struct __attribute__((packed)) U31 {234  char a;235  struct T2 b __attribute__((aligned(4)));236};237 238struct __attribute__((packed)) U32 {239  char a;240  char b;241  char c;242  char d;243  struct T3 e;244};245 246struct __attribute__((packed)) U33 {247  char a;248  char b;249  char c;250  char d;251  struct T2 e __attribute__((aligned(4)));252};253 254struct __attribute__((packed)) U34 {255  char a;256  struct T1 b __attribute__((packed)); // expected-warning {{field b within 'struct U34' is less aligned than 'struct T1' and is usually due to 'struct U34' being packed, which can lead to unaligned accesses}}257  struct T2 c;258};259 260struct __attribute__((packed)) U35 {261  char a;262  struct T4 {263    char b;264    struct T1 c;265  } d; // expected-warning {{field d within 'struct U35' is less aligned than 'struct T4' and is usually due to 'struct U35' being packed, which can lead to unaligned accesses}}266};267 268// Set 5269 270#pragma pack(push, 1)271struct T5 {272  char a;273  struct T1 b; // expected-warning {{field b within 'struct T5' is less aligned than 'struct T1' and is usually due to 'struct T5' being packed, which can lead to unaligned accesses}}274};275#pragma pack(pop)276 277#pragma pack(push, 1)278struct U36 {279  char a;280  struct T5 b;281  int c;282};283 284struct U37 {285  char a;286  struct T3 b; // expected-warning {{field b within 'struct U37' is less aligned than 'struct T3' and is usually due to 'struct U37' being packed, which can lead to unaligned accesses}}287  int c;288};289#pragma pack(pop)290struct U38 {291  char a;292  struct T5 b __attribute__((aligned(4)));293  int c;294};295 296#pragma pack(push, 1)297 298#pragma pack(push, 4)299struct U39 {300  char a;301  struct T5 b;302  int c;303};304#pragma pack(pop)305 306#pragma pack(pop)307 308// Set 6309 310struct __attribute__((packed)) A1 {311  char a;312  struct T1 b; // expected-warning {{field b within 'struct A1' is less aligned than 'struct T1' and is usually due to 'struct A1' being packed, which can lead to unaligned accesses}}313};314 315struct A2 {316  char a;317  struct T1 b;318};319 320struct __attribute__((packed)) A3 {321  char a;322  struct T1 b __attribute__((aligned(4)));323};324 325#pragma pack(push, 1)326struct A4 {327  char a;328  struct T1 b; // expected-warning {{field b within 'struct A4' is less aligned than 'struct T1' and is usually due to 'struct A4' being packed, which can lead to unaligned accesses}}329};330 331struct A5 {332  char a;333  struct T1 b __attribute__((aligned(4))); // expected-warning {{field b within 'struct A5' is less aligned than 'struct T1' and is usually due to 'struct A5' being packed, which can lead to unaligned accesses}}334};335#pragma pack(pop)336 337struct __attribute__((packed)) A6 {338  struct T1 a;339};340 341struct A7 {342  char a;343  struct T1 b __attribute__((packed));344};345 346struct A8 {347  char a;348  char b;349  short c;350  struct T1 d;351};352 353struct A9 {354  char a;355  struct T2 b;356};357 358struct A10 {359  char a;360  struct T2 b __attribute__((aligned(4)));361};362 363struct __attribute__((packed)) A11 {364  char a;365  struct T2 b;366};367 368struct __attribute__((packed)) U40 {369  char a;370  struct A1 b;371  int c;372};373 374struct __attribute__((packed)) U41 {375  char a;376  struct A3 b; // expected-warning {{field b within 'struct U41' is less aligned than 'struct A3' and is usually due to 'struct U41' being packed, which can lead to unaligned accesses}}377  int c;378};379 380#pragma pack(push, 1)381struct U42 {382  char a;383  struct A1 b;384  int c;385};386#pragma pack(pop)387 388struct __attribute__((packed)) U43 {389  char a;390  struct A9 b;391  int c;392};393 394struct __attribute__((packed)) U44 {395  char a;396  struct A10 b; // expected-warning {{field b within 'struct U44' is less aligned than 'struct A10' and is usually due to 'struct U44' being packed, which can lead to unaligned accesses}}397  int c;398};399 400#pragma pack(push, 1)401 402struct U45 {403  char a;404  struct A10 b; // expected-warning {{field b within 'struct U45' is less aligned than 'struct A10' and is usually due to 'struct U45' being packed, which can lead to unaligned accesses}}405  int c;406};407 408#pragma pack(pop)409 410struct __attribute__((packed)) U46 {411  char a;412  struct A2 b; // expected-warning {{field b within 'struct U46' is less aligned than 'struct A2' and is usually due to 'struct U46' being packed, which can lead to unaligned accesses}}413  int c;414};415 416struct __attribute__((packed)) U47 {417  char a;418  struct A8 b; // expected-warning {{field b within 'struct U47' is less aligned than 'struct A8' and is usually due to 'struct U47' being packed, which can lead to unaligned accesses}}419  int c;420};421 422#pragma pack(push, 1)423struct U48 {424  char a;425  struct A8 b; // expected-warning {{field b within 'struct U48' is less aligned than 'struct A8' and is usually due to 'struct U48' being packed, which can lead to unaligned accesses}}426  int c;427};428#pragma pack(pop)429 430struct U49 {431  char a;432  struct A11 b;433  int c;434};435 436struct U50 {437  char a;438  struct A1 b;439  int c;440};441 442struct U51 {443  char a;444  struct A5 b;445  int c;446};447 448struct __attribute__((packed)) U52 {449  char a;450  struct A6 b;451};452 453struct U53 {454  char a;455  struct A4 b;456};457 458struct U54 {459  char b;460  struct A7 c;461};462 463struct U1 s1;464struct U2 s2;465struct U3 s3;466struct U4 s4;467struct U5 s5;468struct U6 s6;469struct U7 s7;470struct U8 s8;471struct U9 s9;472struct U10 s10;473struct U11 s11;474struct U12 s12;475struct U13 s13;476struct U14 s14;477struct U15 s15;478struct U16 s16;479struct U17 s17;480struct U18 s18;481struct U19 s19;482struct U20 s20;483struct U21 s21;484struct U22 s22;485struct U23 s23;486struct U24 s24;487struct U25 s25;488struct U26 s26;489struct U27 s27;490struct U28 s28;491struct U29 s29;492struct U30 s30;493struct U31 s31;494struct U32 s32;495struct U33 s33;496struct U34 s34;497struct U35 s35;498struct U36 s36;499struct U37 s37;500struct U38 s38;501struct U39 s39;502struct U40 s40;503struct U41 s41;504struct U42 s42;505struct U43 s43;506struct U44 s44;507struct U45 s45;508struct U46 s46;509struct U47 s47;510struct U48 s48;511struct U49 s49;512struct U50 s50;513struct U51 s51;514struct U52 s52;515struct U53 s53;516struct U54 s54;517