https://gcc.gnu.org/bugzilla/show_bug.cgi?id=79364
Bug ID: 79364
Summary: some variadic functions miscompiled (at least for x64
targets)
Product: gcc
Version: unknown
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: xilun0 at gmail dot com
Target Milestone: ---
Hello,
G++ miscompiles the following program at least for x64, at least from gcc 4.7
to 7.0 20170115
Compiling with or without O2 changes the observed behavior (segfault or
garbage) but the program is miscompiled in both cases.
gcc seems to compile the corresponding C program correctly.
The expected output is: 1 2 3 4 5 6 coucou
The actual "output" is a segfault or some garbage instead of "coucou"
Cheers!
#include <cstdarg>
#include <cstdio>
struct vatag {};
void tst(vatag tag, ...)
{
int i;
va_list ap;
va_start(ap, tag);
#define P_INT i = va_arg(ap, int); printf("%i ", i);
P_INT P_INT P_INT P_INT P_INT P_INT
const char* s = va_arg(ap, char*); printf("%s\n", s);
va_end(ap);
}
int main(void)
{
tst(vatag{}, 1, 2, 3, 4, 5, 6, "coucou");
}