[llvm] ce0c1f3 - [DebugInfo] Fix crash when emitting an invalidated SDDbgValue

Stephen Tozer via llvm-commits llvm-commits at lists.llvm.org
Fri May 7 05:14:34 PDT 2021


Author: Stephen Tozer
Date: 2021-05-07T13:13:56+01:00
New Revision: ce0c1f3ced9bccb29c34b87de82c5cdffcbcd457

URL: https://github.com/llvm/llvm-project/commit/ce0c1f3ced9bccb29c34b87de82c5cdffcbcd457
DIFF: https://github.com/llvm/llvm-project/commit/ce0c1f3ced9bccb29c34b87de82c5cdffcbcd457.diff

LOG: [DebugInfo] Fix crash when emitting an invalidated SDDbgValue

This patch fixes a crash in the compiler that occurs when certain
invalidated SDDbgValues are emitted. The cause of this was that we would
attempt to check the liveness of the debug value's operands, which
triggers an assert if any of those operands are invalid. This patch
changes this check such that it only occurs if the SDDbgValue is valid;
if not, the check is irrelevant anyway, so can be safely ignored.

Differential Revision: https://reviews.llvm.org/D101540

Added: 
    llvm/test/DebugInfo/Generic/invalidated-dbg-value-is-undef.ll

Modified: 
    llvm/lib/CodeGen/SelectionDAG/ScheduleDAGSDNodes.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/CodeGen/SelectionDAG/ScheduleDAGSDNodes.cpp b/llvm/lib/CodeGen/SelectionDAG/ScheduleDAGSDNodes.cpp
index dd02ac34326e8..b2a8c8bdd78ca 100644
--- a/llvm/lib/CodeGen/SelectionDAG/ScheduleDAGSDNodes.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/ScheduleDAGSDNodes.cpp
@@ -765,7 +765,7 @@ ProcessSDDbgValues(SDNode *N, SelectionDAG *DAG, InstrEmitter &Emitter,
     // 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)

diff  --git a/llvm/test/DebugInfo/Generic/invalidated-dbg-value-is-undef.ll b/llvm/test/DebugInfo/Generic/invalidated-dbg-value-is-undef.ll
new file mode 100644
index 0000000000000..1c20bd616ff76
--- /dev/null
+++ b/llvm/test/DebugInfo/Generic/invalidated-dbg-value-is-undef.ll
@@ -0,0 +1,53 @@
+; RUN: llc %s --stop-before=finalize-isel -o - | FileCheck %s --implicit-check-not=DBG_VALUE
+
+;; Check that when a debug value is invalidated during Instruction Selection,
+;; we produce an undef DBG_VALUE/DBG_VALUE_LIST.
+
+; CHECK-LABEL: body:
+
+; CHECK: DBG_VALUE_LIST ![[VAR:[0-9]+]]
+; CHECK-SAME: $noreg, $noreg
+
+
+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 i32 @intel_pmu_enable_bts() local_unnamed_addr !dbg !16 {
+entry:
+  %0 = extractvalue { i32, i64 } zeroinitializer, 1
+  %1 = load i32, i32* @intel_pmu_enable_bts_config, align 4
+  call void @llvm.dbg.value(metadata !DIArgList(i64 %0, i32 %1), metadata !20, metadata !DIExpression(DW_OP_LLVM_arg, 0, DW_OP_LLVM_arg, 1, DW_OP_or, DW_OP_stack_value)), !dbg !23
+  ret i32 %1
+}
+
+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", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !4, globals: !5, splitDebugInlining: false, nameTableKind: None)
+!3 = !DIFile(filename: "invalidated-dbg-value-is-undef.ll", directory: "/")
+!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)


        


More information about the llvm-commits mailing list