[LLVMbugs] [Bug 14994] New: AsmPrinter: uint64_t -> unsigned truncation bug

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Fri Jan 18 13:57:00 PST 2013


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

             Bug #: 14994
           Summary: AsmPrinter: uint64_t -> unsigned truncation bug
           Product: new-bugs
           Version: trunk
          Platform: PC
        OS/Version: Linux
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: new bugs
        AssignedTo: unassignedbugs at nondot.org
        ReportedBy: willdtz at gmail.com
                CC: llvmbugs at cs.uiuc.edu
    Classification: Unclassified


Created attachment 9888
  --> http://llvm.org/bugs/attachment.cgi?id=9888
Example used in bug description.

Found while testing out -fsanitize=implicit-integer-conversion (coming soon to
a clang near you?):

/home/wdietz2/llvm/33-src/lib/CodeGen/AsmPrinter/DIE.cpp:229:63: runtime error:
value 4886718345 =[=0x123456789] of type 'uint64_t' (aka 'unsigned long') is
outside the range of representable values of type 'unsigned int'
/home/wdietz2/llvm/33-src/lib/CodeGen/AsmPrinter/DIE.cpp:203:47: runtime error:
value 4886718345 =[=0x123456789] of type 'uint64_t' (aka 'unsigned long') is
outside the range of representable values of type 'unsigned int'

This truncation results in generating wrong encodings of integer constants
larger than 32bits:

$ cat die_test.c
int main() {                          
  unsigned long long val = VAL;
  return 0;
}

(source also attached)

$ bin/clang -O2 -g die_test.c -DVAL=0x123456789ULL -o die_test; objdump -g
die_test|grep -m1 const_value
    <5f>   DW_AT_const_value : 5 byte block: 89 cf 95 9a 2
$ bin/clang -O2 -g die_test.c -DVAL=0x23456789ULL -o die_test; objdump -g
die_test|grep -m1 const_value
    <5f>   DW_AT_const_value : 5 byte block: 89 cf 95 9a 2
$ bin/clang -O2 -g die_test.c -DVAL=0x3456789ULL -o die_test; objdump -g
die_test|grep -m1 const_value                                                   
    <5f>   DW_AT_const_value : 4 byte block: 89 cf 95 1a

The first example shows the value generated for a 64bit constant, which as can
be seen in the second example is the encoding of that value truncated to
32bits.  The third example is included only to briefly demonstrate that
changing the constant used does change the value generated :).

Changing AsmPrinter::EmitULEB128 and others to take a uint64_t instead of
unsigned should fix this, although there might be other places as well
(sanitizers only catch issues that are actually encountered; I'm not fuzzing).

Let me know if you have any questions or need further information.

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