Here is the function:
Code: Select all
void test(uint32_t a, uint32_t b)
{
uint32_t *arg = &a;
for (uint32_t i = 0; i < 4; ++i) {
printf("%h: %h\n", arg + i, *(arg + i));
}
}
Code: Select all
test(0, 1);
With O1 or no optimization:
0x0001ffe0: 0x00000000
0x0001ffe4: 0x00000001
Here the second argument is passed correctly.
With O2 or O3 optimization:
0x0001ffec: 0x00000000
0x0001fff0: 0x000025bc
Here the second argument is not passed and 0x25bc is just some random stuff.
It seems that with O2/O3 optimization GCC notices that I am not using the second argument in the function and just does not pass it. The reason I am using the pointer to access arguments is that I further would like to use a variable number of arguments.
Is there any kind of attribute to use on the function or another trick to force GCC to pass arguments even if there are not used? I would of course like to keep optimizations.
Regards