我尝试编译以下函数以查看 gcc 对其做了什么:
#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;
}
然后发现 gcc 用尽了我的内存,将自己交换到死。
我发现在优化 -O3
时会发生这种情况,但没有尝试剖析负责的确切标志。在 gcc.godbolt 上测试函数表明这是 gcc 特定的,但影响 4.8 和 4.9 版本。
这是真正的编译器错误,还是我的功能损坏了?
最佳答案
错误在 gcc bugzilla 上,https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65518 .它已被确认并且显然已固定在后备箱中。希望修复最终会渗透到我的发行版中。谢谢大家!
关于c - gcc在优化-O3时消耗所有内存,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29200652/