mem_struct.c (704B)
1 /* mem: loads/stores to struct fields at mixed widths and offsets. A volatile 2 * struct defeats SROA so the fields are really spilled to and reloaded from 3 * memory at their byte offsets, exercising the narrow + wide load/store forms 4 * with base+offset addressing (sturb/ldurb, sturh/ldurh, stur/ldur w and x; 5 * plus scaled ldrh `[base, #2]` when a field is addressed through a pointer). 6 * b = 1, h = 2, w = 9, q = 30 -> 1+2+9+30 = 42 */ 7 struct S { 8 unsigned char b; 9 unsigned short h; 10 unsigned int w; 11 unsigned long q; 12 }; 13 int test_main(void) { 14 volatile struct S s; 15 s.b = 1; 16 s.h = 2; 17 s.w = 9; 18 s.q = 30; 19 unsigned long sum = (unsigned long)s.b + s.h + s.w + s.q; 20 return (int)sum; 21 }