[PATCH] D101540: [DebugInfo] Fix crash when emitting an invalidated SDDbgValue

Stephen Tozer via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Apr 29 08:28:07 PDT 2021


StephenTozer created this revision.
StephenTozer added reviewers: dblaikie, Orlando, probinson, aprantl, vsk.
StephenTozer added a project: debug-info.
Herald added subscribers: ormris, hiraditya, kristof.beyls, MatzeB.
StephenTozer requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

This patch resolves an issue reported in review https://reviews.llvm.org/D91722 (post-commit). The error in this case is simple: during the lambda function `hasUnknownVReg`, used to determine whether an `SDDbgValue` has any unresolved VReg arguments, constructs an `SDValue` from any `SDNode` operands to the debug value. The constructor for an `SDValue` asserts that it is a valid value; this means that when a debug value has an invalid operand, this check will trigger that assertion and crash the compiler.

The solution in this patch is to only perform this check if `!SDDbgValue->isInvalidated()`; the check is irrelevant for an invalidated debug value in the first place, because we will set all of its operands to `undef`, so it doesn't matter whether any of its arguments are unresolved at that point. This check is not used to determine the "correct" insert location for a DBG_VALUE, only the first location where it can be valid, so there should be no harm in short-circuiting this way.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D101540

Files:
  llvm/lib/CodeGen/SelectionDAG/ScheduleDAGSDNodes.cpp
  llvm/test/DebugInfo/Generic/invalidated-dbg-value-is-undef.ll


Index: llvm/test/DebugInfo/Generic/invalidated-dbg-value-is-undef.ll
===================================================================
--- /dev/null
+++ llvm/test/DebugInfo/Generic/invalidated-dbg-value-is-undef.ll
@@ -0,0 +1,59 @@
+; RUN: llc %s --stop-before=finalize-isel -o - | FileCheck %s
+
+;; Check that when a debug value is invalidated during Instruction Selection,
+;; we produce an undef DBG_VALUE/DBG_VALUE_LIST.
+
+; CHECK-LABEL: body:
+; CHECK-NOT: DBG_VALUE
+
+; CHECK: DBG_VALUE_LIST ![[VAR:[0-9]+]]
+; CHECK-SAME: $noreg, $noreg, $noreg
+
+; CHECK-NOT: DBG_VALUE
+
+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"
+
+ at intel_pmu_enable_bts_config = external dso_local local_unnamed_addr global i32, align 4, !dbg !0
+
+define dso_local void @intel_pmu_enable_bts() local_unnamed_addr !dbg !16 {
+entry:
+  %asmresult1 = extractvalue { i32, i64 } zeroinitializer, 1
+  %0 = load i32, i32* @intel_pmu_enable_bts_config, align 4
+  %and = lshr i32 %0, 4
+  %1 = and i32 %and, 1
+  call void @llvm.dbg.value(metadata !DIArgList(i64 %asmresult1, i32 %1, i64 0), metadata !20, metadata !DIExpression(DW_OP_LLVM_arg, 0, DW_OP_LLVM_arg, 2, DW_OP_or, DW_OP_LLVM_arg, 1, DW_OP_LLVM_convert, 32, DW_ATE_unsigned, DW_OP_LLVM_convert, 64, DW_ATE_unsigned, DW_OP_or, DW_OP_stack_value)), !dbg !23
+  %conv8 = or i32 %1, 0
+  tail call void asm sideeffect ".pushsection .discard.retpoline_safe\0A\09.popsection\0A", "{si},~{dirflag},~{fpsr},~{flags}"(i32 %conv8) #2
+  ret void
+}
+
+declare void @llvm.dbg.value(metadata, metadata, metadata)
+
+!llvm.dbg.cu = !{!2}
+!llvm.module.flags = !{!14, !15}
+
+!0 = !DIGlobalVariableExpression(var: !1, expr: !DIExpression())
+!1 = distinct !DIGlobalVariable(name: "intel_pmu_enable_bts_config", scope: !2, file: !3, line: 1, type: !8, isLocal: false, isDefinition: true)
+!2 = distinct !DICompileUnit(language: DW_LANG_C99, file: !3, producer: "clang version 13.0.0 (https://github.com/llvm/llvm-project.git 2e1150d8aad60a8a127c10d9cd48c31334493ebf)", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !4, globals: !5, splitDebugInlining: false, nameTableKind: None)
+!3 = !DIFile(filename: "../ds.i", directory: "/home/stozer/dev/llvm-project/build")
+!4 = !{}
+!5 = !{!0, !6, !9, !11}
+!6 = !DIGlobalVariableExpression(var: !7, expr: !DIExpression())
+!7 = distinct !DIGlobalVariable(name: "intel_pmu_enable_bts___trans_tmp_1", scope: !2, file: !3, line: 1, type: !8, isLocal: false, isDefinition: true)
+!8 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
+!9 = !DIGlobalVariableExpression(var: !10, expr: !DIExpression())
+!10 = distinct !DIGlobalVariable(name: "intel_pmu_enable_bts___ecx", scope: !2, file: !3, line: 2, type: !8, isLocal: false, isDefinition: true)
+!11 = !DIGlobalVariableExpression(var: !12, expr: !DIExpression())
+!12 = distinct !DIGlobalVariable(name: "intel_pmu_enable_bts___eax", scope: !2, file: !3, line: 3, type: !13, isLocal: false, isDefinition: true)
+!13 = !DIBasicType(name: "long int", size: 64, encoding: DW_ATE_signed)
+!14 = !{i32 2, !"Debug Info Version", i32 3}
+!15 = !{i32 7, !"uwtable", i32 1}
+!16 = distinct !DISubprogram(name: "intel_pmu_enable_bts", scope: !3, file: !3, line: 4, type: !17, scopeLine: 4, flags: DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !2, retainedNodes: !19)
+!17 = !DISubroutineType(types: !18)
+!18 = !{!8}
+!19 = !{!20, !21}
+!20 = !DILocalVariable(name: "debugctlmsr", scope: !16, file: !3, line: 5, type: !13)
+!21 = !DILocalVariable(name: "low", scope: !16, file: !3, line: 17, type: !22)
+!22 = !DIBasicType(name: "unsigned int", size: 32, encoding: DW_ATE_unsigned)
+!23 = !DILocation(line: 0, scope: !16)
Index: llvm/lib/CodeGen/SelectionDAG/ScheduleDAGSDNodes.cpp
===================================================================
--- llvm/lib/CodeGen/SelectionDAG/ScheduleDAGSDNodes.cpp
+++ llvm/lib/CodeGen/SelectionDAG/ScheduleDAGSDNodes.cpp
@@ -765,7 +765,7 @@
     // node yet. In the former case we should emit an undef dbg_value, but we
     // can do it later. And for the latter we'll want to wait until all
     // dependent nodes have been visited.
-    if (HasUnknownVReg(DV))
+    if (!DV->isInvalidated() && HasUnknownVReg(DV))
       continue;
     MachineInstr *DbgMI = Emitter.EmitDbgValue(DV, VRBaseMap);
     if (!DbgMI)


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D101540.341521.patch
Type: text/x-patch
Size: 4430 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210429/36768beb/attachment.bin>


More information about the llvm-commits mailing list