From a90ffe0a21a3a813df4eb9a4dc23b06f50699cde Mon Sep 17 00:00:00 2001 From: Xavier Leroy Date: Fri, 20 Mar 2015 16:43:14 +0100 Subject: Support va_arg for vararg arguments of composite (struct/union) types. ARM is done, IA32 and PowerPC remain to be updated. --- test/regression/Results/varargs2 | 4 +++- test/regression/varargs2.c | 16 +++++++++++++++- 2 files changed, 18 insertions(+), 2 deletions(-) (limited to 'test') diff --git a/test/regression/Results/varargs2 b/test/regression/Results/varargs2 index f954927e..96ee9d63 100644 --- a/test/regression/Results/varargs2 +++ b/test/regression/Results/varargs2 @@ -2,7 +2,9 @@ An int: 42 A long long: 123456789012345 A string: Hello world A double: 3.141592654 -A mixture: x & Hello, world! & 42 & 123456789012345 & 3.141592654 & 2.718281746 +A small struct: x12 +A bigger struct: (123,456,789) +A mixture: x & Hello, world! & y2 & 42 & 123456789012345 & 3.141592654 & 2.718281746 Twice: -1 1.23 Twice: -1 1.23 With va_copy: -1 1.23 diff --git a/test/regression/varargs2.c b/test/regression/varargs2.c index 6c091d8b..b96d1940 100644 --- a/test/regression/varargs2.c +++ b/test/regression/varargs2.c @@ -1,6 +1,9 @@ #include #include +struct Y { char kind; unsigned char num; }; +struct Z { int x, y, z; }; + void minivprintf(const char * fmt, va_list ap) { char c; @@ -32,6 +35,14 @@ void minivprintf(const char * fmt, va_list ap) case 'f': printf("%.10g", (float) va_arg(ap, double)); break; + case 'y': + { struct Y s = va_arg(ap, struct Y); + printf("%c%d", s.kind, s.num); + break; } + case 'z': + { struct Z s = va_arg(ap, struct Z); + printf("(%d,%d,%d)", s.x, s.y, s.z); + break; } default: puts(""); return; @@ -111,9 +122,12 @@ int main() miniprintf("A long long: %l\n", 123456789012345LL); miniprintf("A string: %s\n", "Hello world"); miniprintf("A double: %e\n", 3.141592654); - miniprintf("A mixture: %c & %s & %d & %l & %e & %f\n", + miniprintf("A small struct: %y\n", (struct Y) { 'x', 12 }); + miniprintf("A bigger struct: %z\n", (struct Z) { 123, 456, 789 }); + miniprintf("A mixture: %c & %s & %y & %d & %l & %e & %f\n", 'x', "Hello, world!", + (struct Y) { 'y', 2 }, 42, 123456789012345LL, 3.141592654, -- cgit