diff --git a/llvm/lib/CodeGen/AsmPrinter/ByteStreamer.h b/llvm/lib/CodeGen/AsmPrinter/ByteStreamer.h --- a/llvm/lib/CodeGen/AsmPrinter/ByteStreamer.h +++ b/llvm/lib/CodeGen/AsmPrinter/ByteStreamer.h @@ -33,7 +33,7 @@ virtual void emitSLEB128(uint64_t DWord, const Twine &Comment = "") = 0; virtual void emitULEB128(uint64_t DWord, const Twine &Comment = "", unsigned PadTo = 0) = 0; - virtual void emitDIERef(const DIE &D) = 0; + virtual unsigned emitDIERef(const DIE &D) = 0; }; class APByteStreamer final : public ByteStreamer { @@ -55,11 +55,14 @@ AP.OutStreamer->AddComment(Comment); AP.emitULEB128(DWord, nullptr, PadTo); } - void emitDIERef(const DIE &D) override { + unsigned emitDIERef(const DIE &D) override { uint64_t Offset = D.getOffset(); static constexpr unsigned ULEB128PadSize = 4; assert(Offset < (1ULL << (ULEB128PadSize * 7)) && "Offset wont fit"); emitULEB128(Offset, "", ULEB128PadSize); + // Return how many comments to skip in DwarfDebug::emitDebugLocEntry to keep + // comments aligned with debug loc entries. + return ULEB128PadSize; } }; @@ -78,7 +81,10 @@ unsigned PadTo) override { Hash.addULEB128(DWord); } - void emitDIERef(const DIE &D) override { Hash.hashRawTypeReference(D); } + unsigned emitDIERef(const DIE &D) override { + Hash.hashRawTypeReference(D); + return 0; // Only used together with the APByteStreamer. + } }; class BufferByteStreamer final : public ByteStreamer { @@ -125,11 +131,12 @@ Comments.push_back(""); } } - void emitDIERef(const DIE &D) override { + unsigned emitDIERef(const DIE &D) override { uint64_t Offset = D.getOffset(); static constexpr unsigned ULEB128PadSize = 4; assert(Offset < (1ULL << (ULEB128PadSize * 7)) && "Offset wont fit"); emitULEB128(Offset, "", ULEB128PadSize); + return 0; // Only used together with the APByteStreamer. } }; diff --git a/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp b/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp --- a/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp +++ b/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp @@ -2539,7 +2539,12 @@ if (Op.getDescription().Op[I] == Encoding::SizeNA) continue; if (Op.getDescription().Op[I] == Encoding::BaseTypeRef) { - Streamer.emitDIERef(*CU->ExprRefedBaseTypes[Op.getRawOperand(I)].Die); + unsigned Length = + Streamer.emitDIERef(*CU->ExprRefedBaseTypes[Op.getRawOperand(I)].Die); + // Make sure comments stay aligned. + for (unsigned J = 0; J < Length; ++J) + if (Comment != End) + Comment++; } else { for (uint64_t J = Offset; J < Op.getOperandEndOffset(I); ++J) Streamer.emitInt8(Data.getData()[J], Comment != End ? *(Comment++) : ""); diff --git a/llvm/test/DebugInfo/X86/convert-loclist.ll b/llvm/test/DebugInfo/X86/convert-loclist.ll --- a/llvm/test/DebugInfo/X86/convert-loclist.ll +++ b/llvm/test/DebugInfo/X86/convert-loclist.ll @@ -19,6 +19,16 @@ ; extra bytes would be emitted into the output assembly in no ; particular/intentional section - so let's check they don't show up at all: ; ASM-NOT: .asciz "\200\200\200" +; ASM: .byte 10 # Loc expr size +; ASM-NEXT: .byte 17 # DW_OP_consts +; ASM-NEXT: .byte 7 # 7 +; ASM-NEXT: .byte 48 # DW_OP_lit0 +; ASM-NEXT: .byte 34 # DW_OP_plus +; ASM-NEXT: .byte 168 # DW_OP_convert +; ASM-NEXT: .asciz "\232\200\200" # +; ASM-NEXT: .byte 159 # DW_OP_stack_value +; ASM-NEXT: .byte 0 # DW_LLE_end_of_list +; ASM-NOT: .asciz "\200\200\200" ; CHECK: 0x{{0*}}[[TYPE:.*]]: DW_TAG_base_type ; CHECK-NEXT: DW_AT_name ("DW_ATE_unsigned_32")