diff options
| author | NAKAMURA Takumi <geek4civic@gmail.com> | 2011-10-28 14:12:22 +0000 |
|---|---|---|
| committer | NAKAMURA Takumi <geek4civic@gmail.com> | 2011-10-28 14:12:22 +0000 |
| commit | 29ccdd8207ed09e7fb93d4c8fd415502f52dc9a3 (patch) | |
| tree | be3556ba32a9b84a508a1a871b1f0222b8725be2 | |
| parent | f1b4e0052f7e7cbbc02c42825abfbb368c3c209f (diff) | |
| download | bcm5719-llvm-29ccdd8207ed09e7fb93d4c8fd415502f52dc9a3.tar.gz bcm5719-llvm-29ccdd8207ed09e7fb93d4c8fd415502f52dc9a3.zip | |
Dwarf: [PR11022] Fix emitting DW_AT_const_value(>i64), to be host-endian-neutral.
Don't assume APInt::getRawData() would hold target-aware endianness nor host-compliant endianness. rawdata[0] holds most lower i64, even on big endian host.
FIXME: Add a testcase for big endian target.
FIXME: Ditto on CompileUnit::addConstantFPValue() ?
llvm-svn: 143194
| -rw-r--r-- | llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp | 16 | ||||
| -rw-r--r-- | llvm/test/CodeGen/X86/dbg-i128-const.ll | 2 |
2 files changed, 10 insertions, 8 deletions
diff --git a/llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp b/llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp index f9f1642b2ff..95f1f92fe3d 100644 --- a/llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp +++ b/llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp @@ -534,18 +534,20 @@ bool CompileUnit::addConstantValue(DIE *Die, const ConstantInt *CI, // Get the raw data form of the large APInt. const APInt Val = CI->getValue(); - const char *Ptr = (const char*)Val.getRawData(); + const uint64_t *Ptr64 = Val.getRawData(); int NumBytes = Val.getBitWidth() / 8; // 8 bits per byte. bool LittleEndian = Asm->getTargetData().isLittleEndian(); - int Incr = (LittleEndian ? 1 : -1); - int Start = (LittleEndian ? 0 : NumBytes - 1); - int Stop = (LittleEndian ? NumBytes : -1); // Output the constant to DWARF one byte at a time. - for (; Start != Stop; Start += Incr) - addUInt(Block, 0, dwarf::DW_FORM_data1, - (unsigned char)0xFF & Ptr[Start]); + for (int i = 0; i < NumBytes; i++) { + uint8_t c; + if (LittleEndian) + c = Ptr64[i / 8] >> (8 * (i & 7)); + else + c = Ptr64[(NumBytes - 1 - i) / 8] >> (8 * ((NumBytes - 1 - i) & 7)); + addUInt(Block, 0, dwarf::DW_FORM_data1, c); + } addBlock(Die, dwarf::DW_AT_const_value, 0, Block); return true; diff --git a/llvm/test/CodeGen/X86/dbg-i128-const.ll b/llvm/test/CodeGen/X86/dbg-i128-const.ll index fb83fca4b7e..bd96d9195d0 100644 --- a/llvm/test/CodeGen/X86/dbg-i128-const.ll +++ b/llvm/test/CodeGen/X86/dbg-i128-const.ll @@ -1,4 +1,4 @@ -; RUN: llc < %s | FileCheck %s +; RUN: llc -mtriple=x86_64-linux < %s | FileCheck %s ; CHECK: DW_AT_const_value ; CHECK-NEXT: 42 |

