This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c++/43247] New: Icorrect optimization while declaring array[1]


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]