Skip to content

Commit

Permalink
[DPWBS-1149] fix(FrameLowering): skip debug instructions in processFu…
Browse files Browse the repository at this point in the history
…nctionBeforeFrameFinalized

This fixes a crash when building with debug info enabled when a debug instruction
uses the stack.
  • Loading branch information
gargaroff authored and konstantinschwarz committed Mar 27, 2020
1 parent 63e2661 commit 3a20f73
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 0 deletions.
4 changes: 4 additions & 0 deletions llvm/lib/Target/TriCore/TriCoreFrameLowering.cpp
Expand Up @@ -367,6 +367,10 @@ void TriCoreFrameLowering::processFunctionBeforeFrameFinalized(
unsigned OffsetBits = -1;
for (const MachineBasicBlock &MBB : MF) {
for (const MachineInstr &MI : MBB) {
// Skip debug instructions
if (MI.isDebugInstr())
continue;

// Only look at instructions which have a frame index operand
for (const MachineOperand &MO : MI.operands()) {
if (MO.isFI()) {
Expand Down
3 changes: 3 additions & 0 deletions llvm/lib/Target/TriCore/TriCoreRegisterInfo.cpp
Expand Up @@ -93,6 +93,9 @@ void TriCoreRegisterInfo::eliminateFrameIndex(MachineBasicBlock::iterator II,
const TriCoreInstrInfo *TII =
MF.getSubtarget<TriCoreSubtarget>().getInstrInfo();

assert(!MI.isDebugValue() &&
"DBG_VALUE should have been handled by target-independent code");

// Calculate the offset of the frame index and the frame register
const int FrameIndex = MI.getOperand(FIOperandNum).getIndex();
unsigned FrameReg;
Expand Down
64 changes: 64 additions & 0 deletions llvm/test/CodeGen/TriCore/elim-frame-index-dbg-value.mir
@@ -0,0 +1,64 @@
# NOTE: Assertions have been autogenerated by utils/update_mir_test_checks.py
# RUN: llc -mtriple=tricore -run-pass=prologepilog -verify-machineinstrs %s -o - | FileCheck %s

# Check that a DBG_VALUE instruction with a frame index operand does not cause
# a crash before and during frame-index elimination.

--- |
; Function Attrs: noinline nounwind optnone
define dso_local void @test_dbg_value_ignored({ double, double }* noalias sret %agg.result, { double, double }* %x) #0 !dbg !7 {
entry:
unreachable
}

attributes #0 = { noinline nounwind optnone "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "frame-pointer"="all" "less-precise-fpmad"="false" "min-legal-vector-width"="0" "no-builtins" "no-infs-fp-math"="false" "no-jump-tables"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="tc2xx" "target-features"="+tc161" "unsafe-fp-math"="false" "use-soft-float"="false" }
attributes #1 = { nounwind readnone speculatable willreturn }
attributes #2 = { "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "frame-pointer"="all" "less-precise-fpmad"="false" "no-builtins" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="tc2xx" "target-features"="+tc161" "unsafe-fp-math"="false" "use-soft-float"="false" }
attributes #3 = { nounwind }
attributes #4 = { nobuiltin "no-builtins" }

!llvm.dbg.cu = !{!0}
!llvm.module.flags = !{!3, !4, !5}
!llvm.ident = !{!6}

!0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang version 11.0.0 (ssh://git@bitbucket-server.software.htc:7999/toolchain/llvm-project.git 1d1bcd3eb2181697497b5c82dc130b85ca9ca9c0)", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, splitDebugInlining: false, nameTableKind: None)
!1 = !DIFile(filename: "/home/jenkins/workspace/toolchain/dinkum-libc/dinkum/source/csinhl.c", directory: "/home/dominik/workspace/playground")
!2 = !{}
!3 = !{i32 7, !"Dwarf Version", i32 4}
!4 = !{i32 2, !"Debug Info Version", i32 3}
!5 = !{i32 1, !"wchar_size", i32 4}
!6 = !{!"clang version 11.0.0 (ssh://git@bitbucket-server.software.htc:7999/toolchain/llvm-project.git 1d1bcd3eb2181697497b5c82dc130b85ca9ca9c0)"}
!7 = distinct !DISubprogram(name: "csinhl", scope: !8, file: !8, line: 6, type: !9, scopeLine: 7, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !2)
!8 = !DIFile(filename: "jenkins/workspace/toolchain/dinkum-libc/dinkum/source/xxcsinh.h", directory: "/home")
!9 = !DISubroutineType(types: !10)
!10 = !{!11, !11}
!11 = !DIDerivedType(tag: DW_TAG_typedef, name: "_Lcomplex", file: !12, line: 89, baseType: !13)
!12 = !DIFile(filename: "jenkins/workspace/toolchain/dinkum-libc/dinkum/include/c/complex.h", directory: "/home")
!13 = !DIBasicType(name: "complex", size: 128, encoding: DW_ATE_complex_float)
!14 = !DILocalVariable(name: "x", arg: 1, scope: !7, file: !8, line: 6, type: !11)
!15 = !DILocation(line: 6, column: 30, scope: !7)

...
---
name: test_dbg_value_ignored
alignment: 1
legalized: true
regBankSelected: true
selected: true
tracksRegLiveness: true
stack:
- { id: 0, name: '', type: spill-slot, offset: 0, size: 4, alignment: 4,
stack-id: default, callee-saved-register: '', callee-saved-restored: true,
debug-info-variable: '', debug-info-expression: '', debug-info-location: '' }
callSites: []
constants: []
machineFunctionInfo: {}
body: |
bb.1.entry:
; CHECK-LABEL: name: test_dbg_value_ignored
; CHECK: $a14 = frame-setup MOVAA_aa $a10
; CHECK: $a10 = frame-setup LEA_aac $a10, -8
; CHECK: frame-setup CFI_INSTRUCTION def_cfa $a14, 0
; CHECK: DBG_VALUE $a14, 0
DBG_VALUE %stack.0, 0, !14, !DIExpression(DW_OP_deref), debug-location !15
...

0 comments on commit 3a20f73

Please sign in to comment.