简体   繁体   English

优化-O3时,gcc会消耗所有内存

[英]gcc consumes all memory when optimizing -O3

I tried to compile the following function to see what gcc made of it: 我试图编译以下函数,以查看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;
}

And found gcc maxing out my memory, swapping itself to death. 并发现gcc耗尽了我的记忆,将自己交换到了死地。
I've found this to happen when optimizing at -O3 , haven't tried to dissect the exact flag(s) responsible. 我发现在-O3进行优化时会发生这种情况,而没有尝试剖析负责的确切标志。 Testing the function on gcc.godbolt reveals this to be gcc specific, but afflicting 4.8 and 4.9 versions. 在gcc.godbolt上测试该功能可以发现这是gcc特定的,但是会影响4.8和4.9版本。
Is this a genuine compiler bug, or is my function broken? 这是真正的编译器错误,还是我的功能坏了?

The bug is on the gcc bugzilla, https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65518 . 该错误位于gcc bugzilla https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65518上 It has been confirmed & apparently fixed in trunk. 它已被确认并明显固定在行李箱中。 Here's hoping the fix eventually trickles down to my distro. 希望此修补程序最终能够深入我的发行版。 Thanks everyone! 感谢大家!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM