[LLVMbugs] [Bug 7784] New: Clang mis-compiles array of unsigned long longs on FreeBSD

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Sun Aug 1 14:17:28 PDT 2010


http://llvm.org/bugs/show_bug.cgi?id=7784

           Summary: Clang mis-compiles array of unsigned long longs on
                    FreeBSD
           Product: clang
           Version: trunk
          Platform: PC
        OS/Version: FreeBSD
            Status: NEW
          Severity: normal
          Priority: P
         Component: Driver
        AssignedTo: unassignedclangbugs at nondot.org
        ReportedBy: ed at extraordinarymachine.nl
                CC: llvmbugs at cs.uiuc.edu


This is not strictly a clang bug.

The follwing source:

#include <stdio.h>

unsigned long long globalArray[] = {0xFFFFFFFD00000000uLL};

int main()
{
    unsigned long long t = 0xFFFFFFFD00000000uLL;

    printf("%016llX, %016llu\n", t, t);
    printf("%016llX, %016llu\n",
            globalArray[0], globalArray[0]);

    return 0;
}

results in the following results:

FFFFFFFD00000000, 18446744060824649728
0000FFFD00000000, 0281462091808768

Further investigation by Eli Friedman and Dimitry Andric led to the following
conclusion:

binutils 2.20.1 assembles the following:

    .file    "quadtest.s"
    .type    globalArray, at object
    .data
    .globl    globalArray
    .align    16
globalArray:
    .quad    542196645677236224
    .quad    -12884901888
    .quad    0
    .quad    542196645677236224
    .size    globalArray, 32

wrongly to:

Contents of section .data:
 0000 00000000 fa448607 00000000 fdff0000  .....D..........
 0010 00000000 00000000 00000000 fa448607  .............D..

The built-in assembler for BSD (2.15) produces:
Contents of section .data:
 0000 00000000 fa448607 00000000 fdffffff  .....D..........
 0010 00000000 00000000 00000000 fa448607  .............D..

which is correct.

This is clearly a bug in binutils and has been filed as such.
(http://sourceware.org/bugzilla/show_bug.cgi?id=11867)

Question is whether to work around this in clang. similar to the OpenBSD test
in lib/Target/X86/X86MCAsmInfo.cpp?

Index: lib/Target/X86/X86MCAsmInfo.cpp
===================================================================
--- lib/Target/X86/X86MCAsmInfo.cpp    (revision 109940)
+++ lib/Target/X86/X86MCAsmInfo.cpp    (working copy)
@@ -92,7 +92,7 @@

   // OpenBSD has buggy support for .quad in 32-bit mode, just split into two
   // .words.
  if (T.getOS() == Triple::OpenBSD && T.getArch() == Triple::x86)
     Data64bitsDirective = 0;
 }

-- 
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