https://gcc.gnu.org/bugzilla/show_bug.cgi?id=70892
Bug ID: 70892 Summary: additional memory access generated in loop if destructor is inlined Product: gcc Version: 5.3.1 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: wr0112358 at gmail dot com Target Milestone: --- Created attachment 38388 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=38388&action=edit testcase The attached reduced testcase is compiled differently if a simple raii helper type is used. testcase: double array[expected]; double sum = 0.0; for(int j = 0; j < expected; j++) array[j] = (double)j; g++ -std=c++1y -O2 -Wall -Wextra -Werror double_bug_minimal.cc 400950: f2 0f 58 00 addsd (%rax),%xmm0 400954: 48 83 c0 08 add $0x8,%rax 400958: 48 39 d0 cmp %rdx,%rax 40095b: 75 f3 jne 400950 <main+0x70> g++ -std=c++1y -O2 -Wall -Wextra -Werror -DA double_bug_minimal.cc 400a98: f2 0f 10 4c 24 08 movsd 0x8(%rsp),%xmm1 400a9e: 48 83 c0 08 add $0x8,%rax 400aa2: f2 0f 58 48 f8 addsd -0x8(%rax),%xmm1 400aa7: 48 39 d0 cmp %rdx,%rax 400aaa: f2 0f 11 4c 24 08 movsd %xmm1,0x8(%rsp) 400ab0: 75 e6 jne 400a98 <main+0x78> g++ --version | head -n1; cat /etc/fedora-release; uname -a g++ (GCC) 5.3.1 20160406 (Red Hat 5.3.1-6) Fedora release 23 (Twenty Three) Linux lautreamont 4.4.7-300.fc23.x86_64 #1 SMP Wed Apr 13 02:52:52 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux