Hello all, I am working with a private target(GCC v4.1.1). For my target the function arguments are passed through registers. For this purpose 4 registers are used. If the no. of arguments are more than 4, the remaining arguments are passed through stack.
But for varargs the arguments are pushed into the stack by the caller function. I am getting a execution failure for the following test case. #include <stdio.h> #include <stdarg.h> #define INTEGER_ARG 5 void foo(char *name, int d, int e, int f, int g) { printf("\nname = %s\n13 = %d\n72 = %d\n89 = %d\n5 = %d\n", name,d,e,f,g ); } void bar(char *name, ...) { void **arg; arg = __builtin_apply_args(); __builtin_apply(foo, arg, 24); } int main(void) { bar("eeee", 13, 72, 89, INTEGER_ARG); return 0; } The above testcase is similar to gcc-src/gcc/testsuite/gcc.dg/builtin-apply2.c Looking at the assembly file i find that __builtin_apply_args() is where the problem lies. Even though main pushes all the arguments in the stack __builtin_apply_args is expecting the values in the argument registers. More over when foo is called the arguments are to be passed through registers ("eeee", 13, 72, 89) and stack (INTEGER_ARG). The problem is due to two things. 1. __builtin_apply_args is picking the arguments from the argument registers even though they are not available there since its varargs.So its actually storing garbage values in the block. 2. __builtin_apply_args is storing the arguments, even though garbage, in wrong order in the block. From this block, stored in the wrong order, __builtin_apply passes the arguments to foo, and __builtin_apply function is doing the job properly. Is there any way to control the behavior of __builtin_apply_args? Regards, Shafi