114-struct-ret-many-args.c (1088B)
1 /* Struct return interacting with many args. 2 * 3 * Two pressures at once: 4 * - >4 named args spill from arg regs into stack-staged 5 * outgoing-arg slots. 6 * - The return value is a struct, which on a hidden-pointer ABI 7 * would consume an *additional* arg slot (often arg0). 8 * If both paths exist they must compose; the offsets must not collide. */ 9 10 struct Pair { long a; long b; }; /* 2 words */ 11 12 struct Pair big_combine(int p0, int p1, int p2, int p3, 13 int p4, int p5, int p6, int p7) { 14 struct Pair r; 15 r.a = p0 + p1 + p2 + p3; /* 4 reg-args */ 16 r.b = p4 + p5 + p6 + p7; /* 4 stack-staged args */ 17 return r; 18 } 19 20 int main(int argc, char **argv) { 21 struct Pair r = big_combine(1, 2, 3, 4, 5, 6, 7, 8); 22 if (r.a != 10) return 1; /* 1+2+3+4 */ 23 if (r.b != 26) return 2; /* 5+6+7+8 */ 24 25 /* Same call, second time — staging area must be re-usable. */ 26 struct Pair s = big_combine(10, 20, 30, 40, 50, 60, 70, 80); 27 if (s.a != 100) return 3; 28 if (s.b != 260) return 4; 29 return 0; 30 }