kit

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

call_indirect_ret_struct_direct.c (574B)


      1 /* Return a struct field reached through an indexed pointer. The
      2  * returned aggregate is DIRECT (fits in registers), so the callee
      3  * must load each return part from the OPK_INDIRECT source. */
      4 typedef struct {
      5   unsigned a;
      6   unsigned b;
      7 } Loc;
      8 typedef struct {
      9   Loc loc;
     10   int x;
     11 } Line;
     12 
     13 Loc pick(Line* line, int i) { return line[i].loc; }
     14 
     15 int test_main(void) {
     16   Line lines[2];
     17   lines[0].loc.a = 40u;
     18   lines[0].loc.b = 2u;
     19   lines[0].x = 0;
     20   lines[1].loc.a = 99u;
     21   lines[1].loc.b = 99u;
     22   lines[1].x = 0;
     23   Loc l = pick(lines, 0);
     24   return (int)l.a + (int)l.b;
     25 }