public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/33573] New: over-optimization in 4.1.2
@ 2007-09-27 17:17 dooglus at gmail dot com
2007-09-27 23:02 ` [Bug c++/33573] " dooglus at gmail dot com
` (3 more replies)
0 siblings, 4 replies; 5+ messages in thread
From: dooglus at gmail dot com @ 2007-09-27 17:17 UTC (permalink / raw)
To: gcc-bugs
Compiling the following code with -O2 or higher in g++ 4.1.2 produces incorrect
results. The problem doesn't occur in version 4.2.1.
I compile like this:
g++ -W -Wall -Werror -O2 -fPIC -o gccbug gccbug.cpp
The last line of output should show the number 27, but it shows 0 when
optimizing with -O2.
A tar archive containing the source file and a Makefile to build it is here:
http://dooglus.rincevent.net/random/gccbug.1190912601.tgz
Defining any of FIX0, FIX1 or FIX2 fixes the problem.
Here's the source file:
-----
#include <iostream>
#include <string>
#include <vector>
using namespace std;
struct Vector {
float _x, _y;
Vector(): _x(0), _y(0) {};
float &m(const int &i) { return i?_y:_x; }
};
struct Node {
vector<Node*> nl;
Node() {nl.push_back(this);};
string get_name() const {return "x";};
vector<Node*> get_children() { return nl;};
};
int six() { return 6; }
Vector parse_vector(Node *element)
{
Vector vect;
Node *node = element->get_children()[0];
if(node->get_name()=="x") { // true
#ifdef FIX0
cout << "1. vect.m(0) <= 27" << endl;
#else
printf("1. vect.m(0) <= 27\n");
#endif
vect.m(0)=27;
#ifdef FIX1 // printing the value stops the
over-optimization
cout << "2. vect.m(0) == " << vect.m(0) << endl;
#endif
} else if(six() == 6 && node->get_children().empty()) { // false
exit(0);
return Vector();
}
#ifdef FIX2 // checking the value also stops the over optimization
if (vect.m(0) + vect.m(1) == 24234.657) cout << "har" << endl;
#endif
return vect;
}
int main() {
cout << "3. vect.m(0) == " << parse_vector(new Node).m(0) << " <--
should be 27" << endl;
}
-----
--
Summary: over-optimization in 4.1.2
Product: gcc
Version: 4.1.2
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: dooglus at gmail dot com
GCC build triplet: i486-linux-gnu
GCC host triplet: i486-linux-gnu
GCC target triplet: i486-linux-gnu
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=33573
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug c++/33573] over-optimization in 4.1.2
2007-09-27 17:17 [Bug c++/33573] New: over-optimization in 4.1.2 dooglus at gmail dot com
2007-09-27 23:02 ` [Bug c++/33573] " dooglus at gmail dot com
@ 2007-09-27 23:02 ` dooglus at gmail dot com
2007-12-26 15:25 ` [Bug tree-optimization/33573] [4.1 regression] " reichelt at gcc dot gnu dot org
2007-12-26 16:18 ` reichelt at gcc dot gnu dot org
3 siblings, 0 replies; 5+ messages in thread
From: dooglus at gmail dot com @ 2007-09-27 23:02 UTC (permalink / raw)
To: gcc-bugs
------- Comment #1 from dooglus at gmail dot com 2007-09-27 23:02 -------
Created an attachment (id=14259)
--> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=14259&action=view)
the source file
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=33573
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug c++/33573] over-optimization in 4.1.2
2007-09-27 17:17 [Bug c++/33573] New: over-optimization in 4.1.2 dooglus at gmail dot com
@ 2007-09-27 23:02 ` dooglus at gmail dot com
2007-09-27 23:02 ` dooglus at gmail dot com
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: dooglus at gmail dot com @ 2007-09-27 23:02 UTC (permalink / raw)
To: gcc-bugs
------- Comment #2 from dooglus at gmail dot com 2007-09-27 23:02 -------
Created an attachment (id=14260)
--> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=14260&action=view)
the Makefile
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=33573
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug tree-optimization/33573] [4.1 regression] over-optimization in 4.1.2
2007-09-27 17:17 [Bug c++/33573] New: over-optimization in 4.1.2 dooglus at gmail dot com
2007-09-27 23:02 ` [Bug c++/33573] " dooglus at gmail dot com
2007-09-27 23:02 ` dooglus at gmail dot com
@ 2007-12-26 15:25 ` reichelt at gcc dot gnu dot org
2007-12-26 16:18 ` reichelt at gcc dot gnu dot org
3 siblings, 0 replies; 5+ messages in thread
From: reichelt at gcc dot gnu dot org @ 2007-12-26 15:25 UTC (permalink / raw)
To: gcc-bugs
------- Comment #3 from reichelt at gcc dot gnu dot org 2007-12-26 15:25 -------
The problem only affects the 4.1 branch.
It does not appear on the 4.2 branch or mainline.
--
reichelt at gcc dot gnu dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |reichelt at gcc dot gnu dot
| |org
Status|UNCONFIRMED |NEW
Component|c++ |tree-optimization
Ever Confirmed|0 |1
Keywords| |wrong-code
Known to fail| |4.1.0 4.1.1 4.1.2
Known to work| |4.0.4 4.2.0 4.2.1 4.2.2
| |4.3.0
Last reconfirmed|0000-00-00 00:00:00 |2007-12-26 15:25:34
date| |
Summary|over-optimization in 4.1.2 |[4.1 regression] over-
| |optimization in 4.1.2
Target Milestone|--- |4.1.3
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=33573
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug tree-optimization/33573] [4.1 regression] over-optimization in 4.1.2
2007-09-27 17:17 [Bug c++/33573] New: over-optimization in 4.1.2 dooglus at gmail dot com
` (2 preceding siblings ...)
2007-12-26 15:25 ` [Bug tree-optimization/33573] [4.1 regression] " reichelt at gcc dot gnu dot org
@ 2007-12-26 16:18 ` reichelt at gcc dot gnu dot org
3 siblings, 0 replies; 5+ messages in thread
From: reichelt at gcc dot gnu dot org @ 2007-12-26 16:18 UTC (permalink / raw)
To: gcc-bugs
------- Comment #4 from reichelt at gcc dot gnu dot org 2007-12-26 16:18 -------
Well, actually this seems to be a duplicate of PR 30088.
*** This bug has been marked as a duplicate of 30088 ***
--
reichelt at gcc dot gnu dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|NEW |RESOLVED
Resolution| |DUPLICATE
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=33573
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2007-12-26 16:18 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-09-27 17:17 [Bug c++/33573] New: over-optimization in 4.1.2 dooglus at gmail dot com
2007-09-27 23:02 ` [Bug c++/33573] " dooglus at gmail dot com
2007-09-27 23:02 ` dooglus at gmail dot com
2007-12-26 15:25 ` [Bug tree-optimization/33573] [4.1 regression] " reichelt at gcc dot gnu dot org
2007-12-26 16:18 ` reichelt at gcc dot gnu dot org
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).