Skip to content

Commit ce0c1f3

Browse files
committed
[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
1 parent 280aa34 commit ce0c1f3

File tree

2 files changed

+54
-1
lines changed

2 files changed

+54
-1
lines changed

llvm/lib/CodeGen/SelectionDAG/ScheduleDAGSDNodes.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -765,7 +765,7 @@ ProcessSDDbgValues(SDNode *N, SelectionDAG *DAG, InstrEmitter &Emitter,
765765
// node yet. In the former case we should emit an undef dbg_value, but we
766766
// can do it later. And for the latter we'll want to wait until all
767767
// dependent nodes have been visited.
768-
if (HasUnknownVReg(DV))
768+
if (!DV->isInvalidated() && HasUnknownVReg(DV))
769769
continue;
770770
MachineInstr *DbgMI = Emitter.EmitDbgValue(DV, VRBaseMap);
771771
if (!DbgMI)
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
; RUN: llc %s --stop-before=finalize-isel -o - | FileCheck %s --implicit-check-not=DBG_VALUE
2+
3+
;; Check that when a debug value is invalidated during Instruction Selection,
4+
;; we produce an undef DBG_VALUE/DBG_VALUE_LIST.
5+
6+
; CHECK-LABEL: body:
7+
8+
; CHECK: DBG_VALUE_LIST ![[VAR:[0-9]+]]
9+
; CHECK-SAME: $noreg, $noreg
10+
11+
12+
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
13+
target triple = "x86_64-unknown-linux-gnu"
14+
15+
@intel_pmu_enable_bts_config = external dso_local local_unnamed_addr global i32, align 4, !dbg !0
16+
17+
define dso_local i32 @intel_pmu_enable_bts() local_unnamed_addr !dbg !16 {
18+
entry:
19+
%0 = extractvalue { i32, i64 } zeroinitializer, 1
20+
%1 = load i32, i32* @intel_pmu_enable_bts_config, align 4
21+
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
22+
ret i32 %1
23+
}
24+
25+
declare void @llvm.dbg.value(metadata, metadata, metadata)
26+
27+
!llvm.dbg.cu = !{!2}
28+
!llvm.module.flags = !{!14, !15}
29+
30+
!0 = !DIGlobalVariableExpression(var: !1, expr: !DIExpression())
31+
!1 = distinct !DIGlobalVariable(name: "intel_pmu_enable_bts_config", scope: !2, file: !3, line: 1, type: !8, isLocal: false, isDefinition: true)
32+
!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)
33+
!3 = !DIFile(filename: "invalidated-dbg-value-is-undef.ll", directory: "/")
34+
!4 = !{}
35+
!5 = !{!0, !6, !9, !11}
36+
!6 = !DIGlobalVariableExpression(var: !7, expr: !DIExpression())
37+
!7 = distinct !DIGlobalVariable(name: "intel_pmu_enable_bts___trans_tmp_1", scope: !2, file: !3, line: 1, type: !8, isLocal: false, isDefinition: true)
38+
!8 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
39+
!9 = !DIGlobalVariableExpression(var: !10, expr: !DIExpression())
40+
!10 = distinct !DIGlobalVariable(name: "intel_pmu_enable_bts___ecx", scope: !2, file: !3, line: 2, type: !8, isLocal: false, isDefinition: true)
41+
!11 = !DIGlobalVariableExpression(var: !12, expr: !DIExpression())
42+
!12 = distinct !DIGlobalVariable(name: "intel_pmu_enable_bts___eax", scope: !2, file: !3, line: 3, type: !13, isLocal: false, isDefinition: true)
43+
!13 = !DIBasicType(name: "long int", size: 64, encoding: DW_ATE_signed)
44+
!14 = !{i32 2, !"Debug Info Version", i32 3}
45+
!15 = !{i32 7, !"uwtable", i32 1}
46+
!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)
47+
!17 = !DISubroutineType(types: !18)
48+
!18 = !{!8}
49+
!19 = !{!20, !21}
50+
!20 = !DILocalVariable(name: "debugctlmsr", scope: !16, file: !3, line: 5, type: !13)
51+
!21 = !DILocalVariable(name: "low", scope: !16, file: !3, line: 17, type: !22)
52+
!22 = !DIBasicType(name: "unsigned int", size: 32, encoding: DW_ATE_unsigned)
53+
!23 = !DILocation(line: 0, scope: !16)

0 commit comments

Comments
 (0)