I tried to compile the following function to see what gcc made of it:
#include <stdint.h>
#include <stddef.h>
typedef struct giga
{
uint64_t g[0x10000000];
} giga;
uint64_t addfst(giga const *gptr, size_t num)
{
uint64_t retval = 0;
for (size_t i = 0; i < num; i++)
{
retval += gptr[i].g[0];
}
return retval;
}
And found gcc maxing out my memory, swapping itself to death.
I've found this to happen when optimizing at -O3
, haven't tried to dissect the exact flag(s) responsible. Testing the function on gcc.godbolt reveals this to be gcc specific, but afflicting 4.8 and 4.9 versions.
Is this a genuine compiler bug, or is my function broken?