kit

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

call_indirect_ret_struct_byval.c (541B)


      1 /* Return a big struct (>16B) via sret from an OPK_INDIRECT source.
      2  * The callee must memcpy from `[base + ind.ofs]` through the sret
      3  * pointer, not assume the source is OPK_LOCAL. */
      4 typedef struct {
      5   int a[8];
      6 } Big;
      7 typedef struct {
      8   Big big;
      9   int x;
     10 } Row;
     11 
     12 Big pick(Row* row, int i) { return row[i].big; }
     13 
     14 int test_main(void) {
     15   Row rows[2];
     16   rows[0].big.a[0] = 20;
     17   rows[0].big.a[7] = 22;
     18   rows[0].x = 0;
     19   rows[1].big.a[0] = 99;
     20   rows[1].big.a[7] = 99;
     21   rows[1].x = 0;
     22   Big b = pick(rows, 0);
     23   return b.a[0] + b.a[7];
     24 }