[llvm] 65fbe38 - [DwarfDebug] Restore code that make comments stay aligned in DwarfDebug::emitDebugLocEntry
Bjorn Pettersson via llvm-commits
llvm-commits at lists.llvm.org
Tue Jan 18 00:57:05 PST 2022
Author: Bjorn Pettersson
Date: 2022-01-18T09:46:03+01:00
New Revision: 65fbe38f0a20adac8853cb5123d57d8ce3ef17bc
URL: https://github.com/llvm/llvm-project/commit/65fbe38f0a20adac8853cb5123d57d8ce3ef17bc
DIFF: https://github.com/llvm/llvm-project/commit/65fbe38f0a20adac8853cb5123d57d8ce3ef17bc.diff
LOG: [DwarfDebug] Restore code that make comments stay aligned in DwarfDebug::emitDebugLocEntry
Commit 2bddab25dba8d4b0 removed a piece of code from
DwarfDebug::emitDebugLocEntry that according to code comments
"Make sure comments stay aligned".
This patch restores that piece of code, together with the addition
of some extra checks in an existing lit test to work as a regression
test. Without this patch we incorrectly get
.byte 159 # 0
instead of
.byte 159 # DW_OP_stack_value
Differential Revision: https://reviews.llvm.org/D117441
Added:
Modified:
llvm/lib/CodeGen/AsmPrinter/ByteStreamer.h
llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
llvm/test/DebugInfo/X86/convert-loclist.ll
Removed:
################################################################################
diff --git a/llvm/lib/CodeGen/AsmPrinter/ByteStreamer.h b/llvm/lib/CodeGen/AsmPrinter/ByteStreamer.h
index 7525e5865282b..bd2c60eadd612 100644
--- a/llvm/lib/CodeGen/AsmPrinter/ByteStreamer.h
+++ b/llvm/lib/CodeGen/AsmPrinter/ByteStreamer.h
@@ -33,7 +33,7 @@ class ByteStreamer {
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 @@ class APByteStreamer final : public ByteStreamer {
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 @@ class HashingByteStreamer final : public ByteStreamer {
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 @@ class BufferByteStreamer final : public ByteStreamer {
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
index b129aa1716698..609b568f28beb 100644
--- a/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
+++ b/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
@@ -2539,7 +2539,12 @@ void DwarfDebug::emitDebugLocEntry(ByteStreamer &Streamer,
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
index 56dede02c51d1..e3d5522c7e26c 100644
--- 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")
More information about the llvm-commits
mailing list