[PATCH] D117441: [DwarfDebug] Restore code that make comments stay aligned in DwarfDebug::emitDebugLocEntry

Bjorn Pettersson via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Jan 17 14:21:11 PST 2022


bjope updated this revision to Diff 400644.
bjope added a comment.

Utilize a return value from APByteStreamer::emitDIERef to determine how many comments to skip.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D117441/new/

https://reviews.llvm.org/D117441

Files:
  llvm/lib/CodeGen/AsmPrinter/ByteStreamer.h
  llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
  llvm/test/DebugInfo/X86/convert-loclist.ll


Index: llvm/test/DebugInfo/X86/convert-loclist.ll
===================================================================
--- llvm/test/DebugInfo/X86/convert-loclist.ll
+++ 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")
Index: llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
===================================================================
--- llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
+++ 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++) : "");
Index: llvm/lib/CodeGen/AsmPrinter/ByteStreamer.h
===================================================================
--- llvm/lib/CodeGen/AsmPrinter/ByteStreamer.h
+++ 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.
   }
 };
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D117441.400644.patch
Type: text/x-patch
Size: 4038 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220117/a1de727f/attachment.bin>


More information about the llvm-commits mailing list