kit

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

call_indirect_arg_struct_field.c (861B)


      1 /* Pass a struct field reached through an indexed pointer as a function
      2  * argument. `line[i].loc` lowers to an OPK_INDIRECT source operand —
      3  * the backend's call-arg lowering must load each ABI part from
      4  * `[base, ind.ofs + part->src_offset]`, not panic.
      5  *
      6  * Loc is 8 bytes (one INT ABI part on aa64/x64/rv64), so this exercises
      7  * the single-part DIRECT path; the multi-part variant lives in
      8  * call_indirect_arg_struct_field_two_parts.c. */
      9 typedef struct {
     10   unsigned a;
     11   unsigned b;
     12 } Loc;
     13 typedef struct {
     14   Loc loc;
     15   int x;
     16 } Line;
     17 
     18 int sink(Loc l) { return (int)l.a + (int)l.b; }
     19 
     20 int call_loc(Line* line, int i) { return sink(line[i].loc); }
     21 
     22 int test_main(void) {
     23   Line lines[2];
     24   lines[0].loc.a = 40u;
     25   lines[0].loc.b = 2u;
     26   lines[0].x = 0;
     27   lines[1].loc.a = 99u;
     28   lines[1].loc.b = 99u;
     29   lines[1].x = 0;
     30   return call_loc(lines, 0);
     31 }