[cfe-dev] clang bug? Miscompilation of array of unsigned long long

Edward Meewis ed at extraordinarymachine.nl
Sat Jul 24 07:09:34 PDT 2010


  Hi all,

I was toying around with the compiler-rt library and looking into why 
the udivmoddi4_test fails on FreeBSD and on MinGW when compiled with clang.

I narrowed it down to the initalization of the test array:

-- arrTest.c
#include <stdio.h>

unsigned long long globalArray[4] =
{0x078644FA00000000uLL, 0xFFFFFFFD00000000uLL, 0x0000000000000000uLL, 
0x078644FA00000000uLL};

int main()
{
     unsigned long long t1 = 0xFFFFFFFD00000000uLL;
     unsigned long long t2 = 0xFFFFFFFFFFFFFFFFuLL;
     unsigned long long localArray[4] =
     {0xEFFFFFFD00000000uLL, 0xFFFFFFFD00000000uLL, 
18446744060824649728uLL, 0xFFFFFFFFFFFFFFFFuLL};

     printf("0x%016llX, %016llu\n", t1, t1);
     printf("0x%016llX, %016llu\n", t2, t2);
     printf("globalArray: 0x%016llX, 0x%016llX, 0x%016llX, 0x%016llX\n",
             globalArray[0], globalArray[1], globalArray[2], 
globalArray[3]);
     printf("localArray:  0x%016llX, 0x%016llX,   %16llu, 0x%016llX\n",
             localArray[0], localArray[1], localArray[2], localArray[3]);

     return 0;
}
--- clang -o arrTest arrTest.c

./arrTest
0xFFFFFFFD00000000, 18446744060824649728
0xFFFFFFFFFFFFFFFF, 18446744073709551615
globalArray: 0x078644FA00000000, 0x0000FFFD00000000, 0x0000000000000000, 
0x078644FA00000000
localArray:  0xEFFFFFFD00000000, 0x0000FFFD00000000,    281462091808768, 
0xFFFFFFFFFFFFFFFF
---

The second element should be 0xFFFFFFFD00000000 and not 
0x0000FFFD00000000. Note that is doesn't make any difference whether the 
element is initialized in hex of decimal. The third element of the local 
array is set to 18446744060824649728, but returns 281462091808768. A 
normal variable (t1) is handled correctly.

GCC behaves correctly.

Anybody any ideas what's going on?

Best, Edward



More information about the cfe-dev mailing list