This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/43247] New: Icorrect optimization while declaring array[1]
- From: "ogoffart at kde dot org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 3 Mar 2010 14:36:55 -0000
- Subject: [Bug c++/43247] New: Icorrect optimization while declaring array[1]
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
This code should print "WORKS!!!!" a couple of time. But with -O2, g++ optimize
the condition away.
It works with -O1
Tested with gcc 4.4.3 on linux x86_64 (Archlinux)
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
struct QVectorTypedData
{
int array[1];
};
int main(int , char **)
{
QVectorTypedData *d;
d = static_cast<QVectorTypedData *>(::malloc(sizeof(QVectorTypedData)+
(45-1) * sizeof(int)));
memset(d->array, 0, 45 * sizeof(int));
int *array = d->array;
int count = 0;
for (int i = 0; i < 10; i++) {
fprintf(stderr, "%d %d %d %d\n", i, (i>=3), (i<=8), (i>=3) && (i <=
8));
if (i >= 3 && i <= 8) {
fprintf(stderr, "WORKS!!!\n");
}
array[i] = 4;
}
return 0;
}
--
Summary: Icorrect optimization while declaring array[1]
Product: gcc
Version: 4.4.3
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: ogoffart at kde dot org
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43247