112-struct-ret-2word.c (1036B)
1 /* Struct return — 2 words (16 bytes). 2 * 3 * The cg return path uses one 8-byte return slot loaded into a0 at 4 * function exit. A 2-word struct does not fit; on 5 * most ABIs the second word goes through a1 (or a hidden-pointer 6 * convention is used). This test surfaces whichever path is wired, 7 * or the absence of one. */ 8 9 struct Pair { long a; long b; }; /* 16 bytes */ 10 11 struct Pair make_pair(long a, long b) { 12 struct Pair p; 13 p.a = a; 14 p.b = b; 15 return p; 16 } 17 18 int main(int argc, char **argv) { 19 struct Pair p = make_pair(0x1111111111111111L, 0x2222222222222222L); 20 if (p.a != 0x1111111111111111L) return 1; 21 if (p.b != 0x2222222222222222L) return 2; 22 23 /* Direct field access on the call result. */ 24 if (make_pair(7, 8).a != 7) return 3; 25 if (make_pair(7, 8).b != 8) return 4; 26 27 /* Several calls in succession — exercises spill/reload. */ 28 struct Pair q = make_pair(100, 200); 29 struct Pair r = make_pair(300, 400); 30 if (q.a + q.b + r.a + r.b != 1000) return 5; 31 return 0; 32 }