public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/43247]  New: Icorrect optimization while declaring array[1]
@ 2010-03-03 14:37 ogoffart at kde dot org
  2010-03-03 14:42 ` [Bug c++/43247] " thiago at kde dot org
                   ` (9 more replies)
  0 siblings, 10 replies; 15+ messages in thread
From: ogoffart at kde dot org @ 2010-03-03 14:37 UTC (permalink / raw)
  To: gcc-bugs

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


^ permalink raw reply	[flat|nested] 15+ messages in thread
[parent not found: <bug-43247-4@http.gcc.gnu.org/bugzilla/>]

end of thread, other threads:[~2011-06-27 14:31 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-03-03 14:37 [Bug c++/43247] New: Icorrect optimization while declaring array[1] ogoffart at kde dot org
2010-03-03 14:42 ` [Bug c++/43247] " thiago at kde dot org
2010-03-03 14:44 ` thiago at kde dot org
2010-03-03 16:08 ` [Bug tree-optimization/43247] [4.3/4.4 Regression] " rguenth at gcc dot gnu dot org
2010-03-15 15:03 ` [Bug tree-optimization/43247] [4.3/4.4 Regression] Incorrect " rguenth at gcc dot gnu dot org
2010-03-26 18:46 ` pinskia at gcc dot gnu dot org
2010-03-26 18:54 ` hjl dot tools at gmail dot com
2010-03-26 21:46 ` thiago at kde dot org
2010-03-27 10:46 ` rguenth at gcc dot gnu dot org
2010-03-27 14:25 ` hjl dot tools at gmail dot com
2010-05-22 18:35 ` rguenth at gcc dot gnu dot org
     [not found] <bug-43247-4@http.gcc.gnu.org/bugzilla/>
2010-12-22 10:35 ` thiago at kde dot org
2010-12-22 17:49 ` pinskia at gcc dot gnu.org
2010-12-22 19:55 ` thiago at kde dot org
2011-06-27 14:31 ` rguenth at gcc dot gnu.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).