[Bug c++/93496] New: Miscompile of range-for over braced-init-list in constructor of class with virtual inheritance

2020-01-29 Thread justin.lapolla.hpe at gmail dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=93496

Bug ID: 93496
   Summary: Miscompile of range-for over braced-init-list in
constructor of class with virtual inheritance
   Product: gcc
   Version: unknown
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c++
  Assignee: unassigned at gcc dot gnu.org
  Reporter: justin.lapolla.hpe at gmail dot com
  Target Milestone: ---

Created attachment 47733
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=47733&action=edit
test.ii

When I compile, link, and run the attached test.ii file, I expect the
executable to exit with status 0. Instead, it exits with status 1.

Debugging in GDB shows that the _M_len member of the braced-init-list is not
set correctly. I noticed in the assembly code that _ZN3BarC2Ev correctly sets
_M_len while _ZN3BarC1Ev does not.

Here is the correct code from _ZN3BarC2Ev:

movl   $0x0,-0x34(%rbp) # Set braced-init-list data
movq   $0x0,-0x30(%rbp) # Zero out _M_addr
movq   $0x0,-0x28(%rbp) # Zero out _M_len
movq   $0x1,-0x28(%rbp) # Set _M_len
lea-0x34(%rbp),%rax
mov%rax,-0x30(%rbp) # Set _M_addr

Here is the incorrect code from _ZN3BarC1Ev:

movl   $0x0,-0x34(%rbp) # Set braced-init-list data
movq   $0x0,-0x30(%rbp) # Zero out _M_addr
movq   $0x0,-0x28(%rbp) # Zero out _M_len
#  instruction to set _M_len
lea-0x34(%rbp),%rax
mov%rax,-0x30(%rbp) # Set _M_addr

Version:

---
GNU C++14 (GCC) version 8.1.0 20180502 (Cray Inc.) (x86_64-suse-linux)
compiled by GNU C version 8.1.0 20180502 (Cray Inc.), GMP version
6.0.0, MPFR version 3.1.3, MPC version 1.0.3, isl version isl-0.15-GMP
---

System type:

---
x86_64-suse-linux
---

Configured with:

---
../cray-gcc-8.1.0-201806150759.6677a227493f2/configure
--prefix=/opt/gcc/8.1.0/snos --disable-nls --libdir=/opt/gcc/8.1.0/snos/lib
--enable-languages=c,c++,fortran
--with-gxx-include-dir=/opt/gcc/8.1.0/snos/include/g++
--with-slibdir=/opt/gcc/8.1.0/snos/lib --with-system-zlib --enable-shared
--enable-__cxa_atexit --build=x86_64-suse-linux --with-ppl --with-cloog
--disable-multilib
---

Command line that triggers the bug:

---
g++ test.ii
---

Compiler output (empty):

---
---

[Bug c++/93496] Miscompile of range-for over braced-init-list in constructor of class with virtual inheritance

2020-01-30 Thread justin.lapolla.hpe at gmail dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=93496

--- Comment #2 from Justin LaPolla  ---
1. Was the root cause found and fixed intentionally? Or was it fixed
incidentally because of other unrelated changes that happened to cover the bug?

2. Do you have a regression test in place that would detect this bug if it
appeared in future GCC versions?

3. My current project requires that we compile with GCC 8.1.0. To avoid this
bug, we are disallowing virtual inheritance in our code by compiling with
`-Werror=virtual-inheritance'. Is this sufficient? Can you provide guidance on
how to best avoid hitting this bug in GCC 8.1.0?

[Bug c++/93496] Miscompile of range-for over braced-init-list in constructor of class with virtual inheritance

2020-01-31 Thread justin.lapolla.hpe at gmail dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=93496

--- Comment #5 from Justin LaPolla  ---
I think this may be a duplicate of PR 86669. Thanks for finding it.

> Fixed on trunk by r266893 for PR 86669, which doesn't seem related.

What makes you say it doesn't seem related?