Skip to content

Commit

Permalink
[DebugInfo][SelectionDAG] Do not drop dbg intrinsics with empty metad…
Browse files Browse the repository at this point in the history
…ata locs

Without this patch SelectionDAG silently drops dbg.values using `!{}` operands.

Related to https://discourse.llvm.org/t/auto-undef-debug-uses-of-a-deleted-value

This causes assignment-tracking to behaviour to match non-assignment-tracking
behaviour after a recent change (see D140990).

Reviewed By: jmorse

Differential Revision: https://reviews.llvm.org/D150767
  • Loading branch information
OCHyams committed May 18, 2023
1 parent 13bd96e commit 6c08897
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 8 deletions.
4 changes: 4 additions & 0 deletions llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1147,6 +1147,10 @@ void SelectionDAGBuilder::visit(const Instruction &I) {
It != End; ++It) {
auto *Var = FnVarLocs->getDILocalVariable(It->VariableID);
dropDanglingDebugInfo(Var, It->Expr);
if (It->Values.isKillLocation(It->Expr)) {
handleKillDebugValue(Var, It->Expr, It->DL, SDNodeOrder);
continue;
}
SmallVector<Value *> Values(It->Values.location_ops());
if (!handleDebugValue(Values, Var, It->Expr, It->DL, SDNodeOrder,
It->Values.hasArgList()))
Expand Down
32 changes: 24 additions & 8 deletions llvm/test/DebugInfo/X86/dbg-empty-metadata-lowering.ll
Original file line number Diff line number Diff line change
@@ -1,14 +1,27 @@
; RUN: llc %s -stop-after=finalize-isel -o - | FileCheck %s --implicit-check-not=DBG

; RUN: llc %s -stop-after=finalize-isel -o - \
; RUN: | FileCheck %s --implicit-check-not=DBG --check-prefixes=AT-DISABLED,BOTH
;; Check that dbg.values with empty metadata are treated as kills (i.e. become
;; DBG_VALUE $noreg, ...). dbg.declares with empty metadata location operands
;; should be ignored.

; CHECK: stack: []
; CHECK: DBG_VALUE float 5.000000e+00
; CHECK: @ext
; CHECK: DBG_VALUE $noreg
; CHECK: @ext
; RUN: sed 's/;Uncomment-with-sed//g' < %s \
; RUN: | llc -stop-after=finalize-isel -o - \
; RUN: | FileCheck %s --implicit-check-not=DBG --check-prefixes=AT-ENABLED,BOTH
;; Check the same behaviour occurs with assignment tracking enabled.

;; First ensure assignment tracking is truly unset/set.
; AT-DISABLED: !llvm.module.flags = !{![[DWARFv:[0-9]+]], ![[DEBUGv:[0-9]+]]}
; AT-DISABLED-NOT: !{i32 7, !"debug-info-assignment-tracking", i1 true}
; AT-ENABLED: !llvm.module.flags = !{![[DWARFv:[0-9]+]], ![[DEBUGv:[0-9]+]], ![[AT:[0-9]+]]}
; AT-ENABLED-DAG: ![[AT]] = !{i32 7, !"debug-info-assignment-tracking", i1 true}
; BOTH-DAG: ![[DWARFv]] = !{i32 7, !"Dwarf Version", i32 5}
; BOTH-DAG: ![[DEBUGv]] = !{i32 2, !"Debug Info Version", i32 3}

; BOTH: stack: []
; BOTH: DBG_VALUE float 5.000000e+00
; BOTH: @ext
; BOTH: DBG_VALUE $noreg
; BOTH: @ext

target triple = "x86_64-unknown-linux-gnu"

Expand All @@ -27,7 +40,9 @@ declare void @llvm.dbg.value(metadata, metadata, metadata)
declare void @llvm.dbg.declare(metadata, metadata, metadata)

!llvm.dbg.cu = !{!0}
!llvm.module.flags = !{!2, !3}
!llvm.module.flags = !{!2, !3
;Uncomment-with-sed , !21
}
!llvm.ident = !{!8}

!0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus_14, file: !1, producer: "clang version 16.0.0", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, splitDebugInlining: false, nameTableKind: None)
Expand All @@ -47,3 +62,4 @@ declare void @llvm.dbg.declare(metadata, metadata, metadata)
!18 = !DISubprogram(name: "ext", linkageName: "ext", scope: !1, file: !1, line: 1, type: !10, flags: DIFlagPrototyped, spFlags: DISPFlagOptimized, retainedNodes: !19)
!19 = !{}
!20 = !DILocalVariable(name: "g", scope: !9, file: !1, line: 3, type: !14)
!21 = !{i32 7, !"debug-info-assignment-tracking", i1 true}

0 comments on commit 6c08897

Please sign in to comment.