[Bug tree-optimization/43537] [4.3/4.4 Regression] c++ -O2 optimizes away a branch inside a loop (-ftree-vrp maybe)

falk at debian dot org gcc-bugzilla@gcc.gnu.org
Fri Mar 26 15:30:00 GMT 2010



------- 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



More information about the Gcc-bugs mailing list