kit

kit
git clone https://git.ryansepassi.com/git/kit.git
Log | Files | Refs | README

6_5_16_07_struct_assign_through_ptr.c (622B)


      1 /* Aggregate assignment through a pointer parameter used to force the pointer
      2    into a frame home (its operand was lowered as an address, not a value). A
      3    field read on the same pointer then used the garbage frame slot as a register
      4    base, returning the wrong field at -O1/-O2. */
      5 typedef struct {
      6   int x, y, z, w;
      7 } S;
      8 S src = {10, 20, 30, 40};
      9 
     10 __attribute__((noinline)) static int f(S* p) {
     11   *p = src;    /* AGG_COPY, dst operand = pointer p */
     12   return p->y; /* field read: indirect base = p */
     13 }
     14 
     15 int test_main(void) {
     16   S d;
     17   if (f(&d) != 20) return 1;
     18   if (d.x != 10 || d.w != 40) return 2;
     19   return 42;
     20 }