[LLVMbugs] [Bug 3320] New: volatile array bug in llvm-g++

bugzilla-daemon at cs.uiuc.edu bugzilla-daemon at cs.uiuc.edu
Mon Jan 12 21:19:41 PST 2009


           Summary: volatile array bug in llvm-g++
           Product: new-bugs
           Version: unspecified
          Platform: PC
        OS/Version: Linux
            Status: NEW
          Severity: normal
          Priority: P2
         Component: new bugs
        AssignedTo: unassignedbugs at nondot.org
        ReportedBy: regehr at cs.utah.edu
                CC: llvmbugs at cs.uiuc.edu

We'd expect the compiler to generate code reading each element of a[] twice,
but that is not what happens on Ubuntu Hardy on x86 using r62045.  Oddly,
llvm-gcc gets this case right.

regehr at john-home:~$ cat vol.c
#define N 3

typedef volatile int vint;

int sum(vint a[N]) {
   int sum = 0;
   unsigned i;
   for (i = 0; i < N; i++)
     sum += a[i] + a[i];
   return sum;

regehr at john-home:~$ llvm-g++ -O3 vol.c -S -o - -fomit-frame-pointer

        .ident  "GCC: (GNU) 4.2.1 (Based on Apple Inc. build 5628) (LLVM
        .file   "vol.c"

        .align  16
        .globl  _Z3sumPVi
        .type   _Z3sumPVi, at function
        movl    4(%esp), %eax
        movl    4(%eax), %ecx
        movl    (%eax), %edx
        addl    %edx, %edx
        leal    (%edx,%ecx,2), %ecx
        movl    8(%eax), %eax
        leal    (%ecx,%eax,2), %eax
        .size   _Z3sumPVi, .-_Z3sumPVi

        .section        .note.GNU-stack,"", at progbits
regehr at john-home:~$

Configure bugmail: http://llvm.org/bugs/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.

More information about the llvm-bugs mailing list