agg_ret_sret.c (637B)
1 /* A struct LARGER than 16 bytes (five ints, 20 bytes) returned by value, which 2 * forces the sret (struct-return via hidden pointer in x8) calling convention: 3 * the caller allocates the result slot and passes its address in x8, the callee 4 * stores fields through x8. Exercises the sret lowering on both sides. Sum of 5 * 4+8+10+12+8 = 42. */ 6 struct Five { 7 int a, b, c, d, e; 8 }; 9 __attribute__((noinline)) static struct Five mk5(int base) { 10 struct Five s = {base, base * 2, base * 2 + 2, base * 3, base * 2}; 11 return s; 12 } 13 int test_main(void) { 14 volatile int x = 4; 15 struct Five s = mk5(x); 16 return s.a + s.b + s.c + s.d + s.e; 17 }