[Bug 1662495] [NEW] GCC 5 optimizer produces incorrect code
Egor Suvorov
1662495 at bugs.launchpad.net
Tue Feb 7 12:21:14 UTC 2017
Public bug reported:
Inspired by the following blog post:
http://codeforces.com/blog/entry/50291
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~16.04.4)` (looks like it's the most recent package
available as of February 7, 2017).
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.
** Affects: gcc-5 (Ubuntu)
Importance: Undecided
Status: New
** Attachment added: "a.cpp"
https://bugs.launchpad.net/bugs/1662495/+attachment/4814685/+files/a.cpp
--
You received this bug notification because you are a member of Ubuntu
Foundations Bugs, which is subscribed to gcc-5 in Ubuntu.
https://bugs.launchpad.net/bugs/1662495
Title:
GCC 5 optimizer produces incorrect code
Status in gcc-5 package in Ubuntu:
New
Bug description:
Inspired by the following blog post:
http://codeforces.com/blog/entry/50291
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~16.04.4)` (looks like it's the most recent package
available as of February 7, 2017).
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.
To manage notifications about this bug go to:
https://bugs.launchpad.net/ubuntu/+source/gcc-5/+bug/1662495/+subscriptions
More information about the foundations-bugs
mailing list