The following code fails to detect breaking of strict-aliasing rules correctly:

#include <stdio.h>

int main()
{        
        int i;
        float A[20];

        for (i = 0; i < 20; i++)
        {                                                                       
                A[i] = i;
                unsigned int *p = (unsigned int *)&A[i];
                printf("%d\t%.24f\t0x%08x\n", i, A[i], *p);
        }

        return 0;
}

gcc only gives a warning when compiling with '-Wall -O1'. Yet, compiling with
'-Wall -fstrict-aliasing' seems to produce correct results, even though '-Wall
-O2' breaks the code.


-- 
           Summary: Strict-aliasing misdetection
           Product: gcc
           Version: 4.4.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: strikosn at gmail dot com
 GCC build triplet: x86_64-unknown-linux-gnu
  GCC host triplet: x86_64-unknown-linux-gnu
GCC target triplet: x86_64-unknown-linux-gnu


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

Reply via email to