http://gcc.gnu.org/bugzilla/show_bug.cgi?id=60766
Bug ID: 60766
Summary: Wrong optimization with -O2
Product: gcc
Version: 4.8.2
Status: UNCONFIRMED
Severity: major
Priority: P3
Component: tree-optimization
Assignee: unassigned at gcc dot gnu.org
Reporter: mirzayanovmr at gmail dot com
Created attachment 32546
--> http://gcc.gnu.org/bugzilla/attachment.cgi?id=32546&action=edit
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".