GCC 5 optimizer produces incorrect code
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
gcc-5 (Ubuntu) |
Confirmed
|
Undecided
|
Unassigned | ||
gcc-7 (Ubuntu) |
Fix Released
|
Undecided
|
Unassigned |
Bug Description
Inspired by the following blog post: http://
Attached file is a snippet of code which, when compiled with `g++ a.cpp` produces an executable `a.out`, which runs correctly. But when compiled with `g++ a.cpp -O1` the resulting executable crashes in line 10 (according to GDB). Looks like array out-of-bounds error happens despite corresponding check being present in the code.
We was able to reproduce it on two independent installations of Ubuntu 16.04, compiler version is `gcc version 5.4.0 20160609 (Ubuntu 5.4.0-6ubuntu1~
Steps to reproduce:
1. Download `a.cpp` attached.
2. Run `g++ a.cpp -O1` and ensure that it finished without any errors.
3. You can optionally run `g++ a.cpp -O1 -Wall -Wextra -Werror -pedantic` and ensure that this command finishes without any errors as well.
4. Run `./a.out`.
Expected behavior: program finishes correctly.
Real behavior: program crashes with segmentation fault.
Status changed to 'Confirmed' because the bug affects multiple users.