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
Bugs, which is subscribed to Ubuntu.
https://bugs.launchpad.net/bugs/1662495

Title:
  GCC 5 optimizer produces incorrect code

To manage notifications about this bug go to:
https://bugs.launchpad.net/ubuntu/+source/gcc-5/+bug/1662495/+subscriptions

-- 
ubuntu-bugs mailing list
[email protected]
https://lists.ubuntu.com/mailman/listinfo/ubuntu-bugs

Reply via email to