https://gcc.gnu.org/bugzilla/show_bug.cgi?id=83334

--- Comment #4 from zenith432 at users dot sourceforge.net ---
It's not PR 50818
Here's the source code for sample1
=====
#include <stdio.h>

#define MS_ABI __attribute__((ms_abi))

int funcc(int c, __builtin_ms_va_list ap)
{
        int i, s;

        for (s = 0, i = 0; i < c; ++i)
                s += __builtin_va_arg(ap, int);
        return s;
}

int funcb(int c, __builtin_ms_va_list ap)
{
        __builtin_ms_va_list ap2;
        int r;

        __builtin_ms_va_copy(ap2, ap);
        r = funcc(c, ap2);
        __builtin_ms_va_end(ap2);
        return r;
}

int MS_ABI funca(int c, ...)
{
        __builtin_ms_va_list ap;
        int r;

        __builtin_ms_va_start(ap, c);
        r = funcb(c, ap);
        __builtin_ms_va_end(ap);
        return r;
}

int main(int argc, char** argv)
{
        printf("%d\n", funca(3, 1, 2, 3));
        return 0;
}
=====
funcb is a sysv-abi function that obtains an explicitly typed
__builtin_ms_va_list as a parameter.  The code generated for its invocation of
__builtin_ms_va_copy is incorrect.  I didn't attach the object code, but can be
easily obtained with objdump -d.

PR 50818 began in 2011 as a bug report because at the time the __builtin_ms_va*
family didn't exist.  In code compiled with -mabi=sysv, there was no way to
handle varargs inside a function defined as __attribute__((ms_abi)).
Nowadays, the __builtin_ms_va* family exists, so what remains of 
PR 50818 is a feature request that __builtin_va* family behave like the ABI of
the function it is embedded in instead of according to the global -mabi.

This report is about...
- Passing a __builtin_ms_va_list to a sysv_abi function ... works!
- Calling __builtin_var_arg on a __builtin_ms_va_list inside a sysv_abi
function ... works!
- Calling __builtin_ms_va_copy on a __builtin_ms_va_list inside a sysv_abi
function... doesn't work.

Is this a bug?  An unimplemented feature?  It's your call.

Reply via email to