This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug tree-optimization/43537] [4.3/4.4 Regression] c++ -O2 optimizes away a branch inside a loop (-ftree-vrp maybe)
- From: "falk at debian dot org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 26 Mar 2010 15:30:12 -0000
- Subject: [Bug tree-optimization/43537] [4.3/4.4 Regression] c++ -O2 optimizes away a branch inside a loop (-ftree-vrp maybe)
- References: <bug-43537-18961@http.gcc.gnu.org/bugzilla/>
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
------- Comment #8 from falk at debian dot org 2010-03-26 15:30 -------
This seems to be a problem with the struct hack in QVector. Here is a test
case:
extern "C" {
void *memset(void *s, int c, __SIZE_TYPE__ n);
void *malloc(__SIZE_TYPE__ size);
int printf(const char *format, ...);
void abort(void);
}
void print(int v) {
volatile int x = v;
(void) x;
}
struct QVector {
int p[1];
};
int main() {
int i;
QVector* vect = (QVector*) malloc(1024);
memset(vect->p, 0, 1024);
for (i = 0; i < 4; i++) {
int v = vect->p[i];
if (i >= 3 && i <= 4)
return 0;
print(v);
}
abort();
}
Using "int p[]" instead of "int p[1]" makes the problem go away and is probably
a good workaround.
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43537