[PATCH] D89838: [DebugInfo] Fix legacy ZExt emission when FromBits >= 64 (PR47927)
Vedant Kumar via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Oct 20 17:11:18 PDT 2020
vsk created this revision.
vsk added reviewers: markus, aprantl.
Herald added a subscriber: hiraditya.
Herald added a project: LLVM.
vsk requested review of this revision.
Fix an out-of-bounds shift in emitLegacyZExt by using a slightly more
complicated dwarf expression to create the zext mask.
This addresses a UBSan diagnostic seen when compiling compiler-rt
(llvm.org/PR47927).
rdar://70307714
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D89838
Files:
llvm/lib/CodeGen/AsmPrinter/DwarfExpression.cpp
llvm/test/DebugInfo/X86/legacy-zext.ll
Index: llvm/test/DebugInfo/X86/legacy-zext.ll
===================================================================
--- /dev/null
+++ llvm/test/DebugInfo/X86/legacy-zext.ll
@@ -0,0 +1,33 @@
+; RUN: llc -filetype=obj -o - %s | llvm-dwarfdump - | FileCheck %s
+
+; CHECK: DW_AT_location (DW_OP_breg5 RDI+0, DW_OP_lit1, DW_OP_constu 0x40, DW_OP_shl, DW_OP_lit1, DW_OP_minus, DW_OP_and)
+
+target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-unknown-linux-gnu"
+
+define void @t(i64 %x) !dbg !6 {
+ call void @llvm.dbg.value(metadata i64 %x, metadata !9,
+ metadata !DIExpression(DW_OP_LLVM_convert, 64, DW_ATE_unsigned,
+ DW_OP_LLVM_convert, 128, DW_ATE_unsigned)), !dbg !11
+ ret void, !dbg !12
+}
+
+declare void @llvm.dbg.value(metadata, metadata, metadata)
+
+!llvm.dbg.cu = !{!0}
+!llvm.debugify = !{!3, !4}
+!llvm.module.flags = !{!5}
+
+!0 = distinct !DICompileUnit(language: DW_LANG_C, file: !1, producer: "debugify", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !2)
+!1 = !DIFile(filename: "legacy-zext.ll", directory: "/")
+!2 = !{}
+!3 = !{i64 2}
+!4 = !{i64 1}
+!5 = !{i64 2, !"Debug Info Version", i32 3}
+!6 = distinct !DISubprogram(name: "t", linkageName: "t", scope: null, file: !1, line: 1, type: !7, scopeLine: 1, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !8)
+!7 = !DISubroutineType(types: !2)
+!8 = !{!9}
+!9 = !DILocalVariable(name: "1", scope: !6, file: !1, line: 1, type: !10)
+!10 = !DIBasicType(name: "ty64", size: 32, encoding: DW_ATE_unsigned)
+!11 = !DILocation(line: 1, column: 1, scope: !6)
+!12 = !DILocation(line: 2, column: 1, scope: !6)
Index: llvm/lib/CodeGen/AsmPrinter/DwarfExpression.cpp
===================================================================
--- llvm/lib/CodeGen/AsmPrinter/DwarfExpression.cpp
+++ llvm/lib/CodeGen/AsmPrinter/DwarfExpression.cpp
@@ -651,9 +651,18 @@
}
void DwarfExpression::emitLegacyZExt(unsigned FromBits) {
- // (X & (1 << FromBits - 1))
- emitOp(dwarf::DW_OP_constu);
- emitUnsigned((1ULL << FromBits) - 1);
+ // X & ((1 << FromBits) - 1)
+ if (FromBits < 64) {
+ emitOp(dwarf::DW_OP_constu);
+ emitUnsigned((1ULL << FromBits) - 1);
+ } else {
+ emitOp(dwarf::DW_OP_lit1);
+ emitOp(dwarf::DW_OP_constu);
+ emitUnsigned(FromBits);
+ emitOp(dwarf::DW_OP_shl);
+ emitOp(dwarf::DW_OP_lit1);
+ emitOp(dwarf::DW_OP_minus);
+ }
emitOp(dwarf::DW_OP_and);
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D89838.299521.patch
Type: text/x-patch
Size: 2560 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20201021/7c5dcdff/attachment.bin>
More information about the llvm-commits
mailing list