[Bug c/37745] New: Segmentation Fault Exception with -O and signed array index

gcc at jme dot de gcc-bugzilla@gcc.gnu.org
Mon Oct 6 11:17:00 GMT 2008


The following code produces a segmentation fault when compiled with -O.
Environment is GCC V4.2.2 (also tested with 4.1.2) on AVR32 Linux target.
Cross compiled on Cygwin.
With GCC V3.4.4 on Cygwin Target it works correct.
Even when I insert a printf("."); between the if and the for the code works.

static const unsigned aArr[] = {31,28,31};

unsigned Bla(unsigned u8)
{
    unsigned u32;
    int i,m;

    u32=0;
    m=u8;
    if (m!=0) m--;
    //printf(".");
    for (i=0; i<m; i++) u32+=aArr[i];

    return u32;
}

int main()
{
    Bla(1);
    return 0;
}


-- 
           Summary: Segmentation Fault Exception with -O and signed array
                    index
           Product: gcc
           Version: 4.2.2
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: gcc at jme dot de
  GCC host triplet: Cygwin
GCC target triplet: AVR32 Linux


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=37745



More information about the Gcc-bugs mailing list