Skip to content

Commit f9b4b2a

Browse files
authored
Merge pull request #2060 from vedantk/eng/PR-70307714
[DebugInfo] Fix legacy ZExt emission when FromBits >= 64 (PR47927)
2 parents a6096d9 + 0f777c3 commit f9b4b2a

File tree

3 files changed

+45
-7
lines changed

3 files changed

+45
-7
lines changed

llvm/lib/CodeGen/AsmPrinter/DwarfExpression.cpp

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -558,7 +558,7 @@ void DwarfExpression::addExpression(DIExpressionCursor &&ExprCursor,
558558
if (Encoding == dwarf::DW_ATE_signed)
559559
emitLegacySExt(PrevConvertOp->getArg(0));
560560
else if (Encoding == dwarf::DW_ATE_unsigned)
561-
emitLegacyZExt(PrevConvertOp->getArg(0));
561+
emitLegacyZExt(PrevConvertOp->getArg(0), BitSize);
562562
PrevConvertOp = None;
563563
} else {
564564
PrevConvertOp = Op;
@@ -650,11 +650,17 @@ void DwarfExpression::emitLegacySExt(unsigned FromBits) {
650650
emitOp(dwarf::DW_OP_or);
651651
}
652652

653-
void DwarfExpression::emitLegacyZExt(unsigned FromBits) {
654-
// (X & (1 << FromBits - 1))
655-
emitOp(dwarf::DW_OP_constu);
656-
emitUnsigned((1ULL << FromBits) - 1);
657-
emitOp(dwarf::DW_OP_and);
653+
void DwarfExpression::emitLegacyZExt(unsigned FromBits, unsigned ToBits) {
654+
if (FromBits < 64) {
655+
// X & ((1 << FromBits) - 1)
656+
emitOp(dwarf::DW_OP_constu);
657+
emitUnsigned((1ULL << FromBits) - 1);
658+
emitOp(dwarf::DW_OP_and);
659+
} else {
660+
addOpPiece(FromBits, 0);
661+
emitOp(dwarf::DW_OP_lit0);
662+
addOpPiece(ToBits - FromBits, FromBits);
663+
}
658664
}
659665

660666
void DwarfExpression::addWasmLocation(unsigned Index, uint64_t Offset) {

llvm/lib/CodeGen/AsmPrinter/DwarfExpression.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,7 @@ class DwarfExpression {
351351
void addFragmentOffset(const DIExpression *Expr);
352352

353353
void emitLegacySExt(unsigned FromBits);
354-
void emitLegacyZExt(unsigned FromBits);
354+
void emitLegacyZExt(unsigned FromBits, unsigned ToBits);
355355

356356
/// Emit location information expressed via WebAssembly location + offset
357357
/// The Index is an identifier for locals, globals or operand stack.
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
; RUN: llc -filetype=obj -o - %s | llvm-dwarfdump - | FileCheck %s
2+
3+
; CHECK: DW_AT_location (DW_OP_breg5 RDI+0, DW_OP_piece 0x8, DW_OP_lit0, DW_OP_bit_piece 0x40 0x40)
4+
5+
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
6+
target triple = "x86_64-unknown-linux-gnu"
7+
8+
define void @t(i64 %x) !dbg !6 {
9+
call void @llvm.dbg.value(metadata i64 %x, metadata !9,
10+
metadata !DIExpression(DW_OP_LLVM_convert, 64, DW_ATE_unsigned,
11+
DW_OP_LLVM_convert, 128, DW_ATE_unsigned)), !dbg !11
12+
ret void, !dbg !11
13+
}
14+
15+
declare void @llvm.dbg.value(metadata, metadata, metadata)
16+
17+
!llvm.dbg.cu = !{!0}
18+
!llvm.debugify = !{!3, !4}
19+
!llvm.module.flags = !{!5}
20+
21+
!0 = distinct !DICompileUnit(language: DW_LANG_C, file: !1, producer: "debugify", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !2)
22+
!1 = !DIFile(filename: "legacy-zext.ll", directory: "/")
23+
!2 = !{}
24+
!3 = !{i64 2}
25+
!4 = !{i64 1}
26+
!5 = !{i64 2, !"Debug Info Version", i32 3}
27+
!6 = distinct !DISubprogram(name: "t", linkageName: "t", scope: null, file: !1, line: 1, type: !7, scopeLine: 1, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !8)
28+
!7 = !DISubroutineType(types: !2)
29+
!8 = !{!9}
30+
!9 = !DILocalVariable(name: "1", scope: !6, file: !1, line: 1, type: !10)
31+
!10 = !DIBasicType(name: "ty128", size: 128, encoding: DW_ATE_unsigned)
32+
!11 = !DILocation(line: 1, column: 1, scope: !6)

0 commit comments

Comments
 (0)