[4.7 Regression] Wrong optimization with -O2

Bug #1432250 reported by Muhammad Annaqeeb
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
gcc-4.8 (Ubuntu)
Fix Released
Undecided
Unassigned

Bug Description

As reported by Mike Mirzayanov on GCC Bugzilla:
See https://gcc.gnu.org/bugzilla/show_bug.cgi?id=60766 and http://codeforces.com/blog/entry/11450
Ubuntu 14.04 includes GCC 4.8.2 which is affected with bug.
Please upgrade to GCC 4.8.3 or later in which the bug is fixed.
"
Compile with -O2 and input 9

Compile the following code with -O2:

~~~~~
#include <cstdlib>
#include <iostream>
#include <cstdio>

using namespace std;

int main() {
    int n;
    cin >> n;

    for (int x = 0; x <= n; x++) {
        if (n == x + (x + 1) + (x + 2)) {
            cout << x + 2 << " " << x + 1 << " " << x << endl;
            exit(0);
        }
    }
    cout << -1 << endl;
    return 0;
}
~~~~~

Start binary and enter 9

It will print "-1", but expected output is "4 3 2".
"

Revision history for this message
Muhammad Annaqeeb (annaqeeb) wrote :
affects: gcc (Ubuntu) → gcc-4.8 (Ubuntu)
Revision history for this message
Matthias Klose (doko) wrote :

this is fixed in trusty-updates

Changed in gcc-4.8 (Ubuntu):
status: New → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.