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

             Bug #: 52517
           Summary: Bug in PPC pointer arithmetic
    Classification: Unclassified
           Product: gcc
           Version: 4.6.3
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: target
        AssignedTo: unassig...@gcc.gnu.org
        ReportedBy: jdeme...@cage.ugent.be


Created attachment 26846
  --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=26846
Testcase, file 1

This happens on an OS X 10.4 PPC machine (powerpc-apple-darwin8.11.0) using GCC
4.6.3.  Compile the test program with

gcc bug.c magic.c -O2 -o bug

I would expect the output to be 42, but instead I get 123456789.  Looking at
the pointer arithmetic, M should be equal to L.  So it seems that GCC assumes
that the assignment of L cannot affect M below.

The value of x matters a lot (but it clearly should not).  So far, I only
managed to reproduce the problem when x is a pointer to something, casted to an
unsigned long.

Replacing
    M = *(unsigned long*)(B + x);
by the equivalent
    M = ((unsigned long*)(B))[x/4];
solves the problem.

Might be related to PR49330?

$ gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/Users/jdemeyer/sage-5.0.beta7-gcc/local/libexec/gcc/powerpc-apple-darwin8.11.0/4.6.3/lto-wrapper
Target: powerpc-apple-darwin8.11.0
Configured with: ../src/configure
--prefix=/Users/jdemeyer/sage-5.0.beta7-gcc/local
--with-local-prefix=/Users/jdemeyer/sage-5.0.beta7-gcc/local
--with-gmp=/Users/jdemeyer/sage-5.0.beta7-gcc/local
--with-mpfr=/Users/jdemeyer/sage-5.0.beta7-gcc/local
--with-mpc=/Users/jdemeyer/sage-5.0.beta7-gcc/local --with-system-zlib
--disable-multilib
Thread model: posix
gcc version 4.6.3 (GCC)

Reply via email to