[cfe-dev] clang bug? Miscompilation of array of unsigned long long
Douglas Gregor
dgregor at apple.com
Mon Jul 26 07:23:32 PDT 2010
On Jul 24, 2010, at 7:09 AM, Edward Meewis wrote:
> 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?
No idea, and I'm not able to reproduce it on my platform (Darwin). Could you give me the output of clang -v arrTest.c
and clang -### arrTest.c , so I can get all of the version/triple information?
- Doug
More information about the cfe-dev
mailing list