113-struct-ret-3word.c (1170B)
1 /* Struct return — >2 words (24 bytes). 2 * 3 * Larger than any reasonable register-pair return. Most real ABIs 4 * would use a hidden first-arg pointer (sret/byval) so the callee 5 * stores the result through that pointer. The cg return path doesn't 6 * describe such a convention, so this exercises whatever the code does 7 * today — a loud fail is the expected outcome until a large-return ABI 8 * lands. */ 9 10 struct Triple { long a; long b; long c; }; /* 24 bytes */ 11 12 struct Triple make_triple(long a, long b, long c) { 13 struct Triple t; 14 t.a = a; 15 t.b = b; 16 t.c = c; 17 return t; 18 } 19 20 int main(int argc, char **argv) { 21 struct Triple t = make_triple(10, 20, 30); 22 if (t.a != 10) return 1; 23 if (t.b != 20) return 2; 24 if (t.c != 30) return 3; 25 26 /* Field of inline call result. */ 27 if (make_triple(1, 2, 3).c != 3) return 4; 28 29 /* Two calls back-to-back: caller must allocate a fresh result 30 * area for each so they don't alias. */ 31 struct Triple u = make_triple(100, 200, 300); 32 struct Triple v = make_triple(400, 500, 600); 33 if (u.a + u.b + u.c != 600) return 5; 34 if (v.a + v.b + v.c != 1500) return 6; 35 return 0; 36 }