diff options
author | Jeremy Morse <jeremy.morse@sony.com> | 2021-11-24 10:20:03 +0000 |
---|---|---|
committer | Jeremy Morse <jeremy.morse@sony.com> | 2021-11-24 10:34:48 +0000 |
commit | b8f68ad9cdb11d585acc6c38ad124b32efb6178a (patch) | |
tree | d4e46b155017a6233311b423d64a0eb389d0190f /llvm/lib/CodeGen/MachineFunction.cpp | |
parent | d9af9c2c5a53c9ba6aa0255240a2a40e8bea27aa (diff) | |
download | llvm-b8f68ad9cdb11d585acc6c38ad124b32efb6178a.zip llvm-b8f68ad9cdb11d585acc6c38ad124b32efb6178a.tar.gz llvm-b8f68ad9cdb11d585acc6c38ad124b32efb6178a.tar.bz2 |
[DebugInfo][InstrRef] Avoid crash when values optimised out late in sdag
It appears that we can emit all the instructions for a function, including
debug instructions, and then optimise some of the values out late.
Specifically, in the attached test case, an argument gets optimised out
after DBG_VALUE / DBG_INSTR_REFs are created. This confuses
MachineFunction::finalizeDebugInstrRefs, which expects to be able to find a
defining instruction, and crashes instead.
Fix this by identifying when there's no defining instruction, and
translating that instead into a DBG_VALUE $noreg.
Differential Revision: https://reviews.llvm.org/D114476
Diffstat (limited to 'llvm/lib/CodeGen/MachineFunction.cpp')
-rw-r--r-- | llvm/lib/CodeGen/MachineFunction.cpp | 11 |
1 files changed, 6 insertions, 5 deletions
diff --git a/llvm/lib/CodeGen/MachineFunction.cpp b/llvm/lib/CodeGen/MachineFunction.cpp index 28c645d..310c272 100644 --- a/llvm/lib/CodeGen/MachineFunction.cpp +++ b/llvm/lib/CodeGen/MachineFunction.cpp @@ -1170,9 +1170,10 @@ auto MachineFunction::salvageCopySSA(MachineInstr &MI) void MachineFunction::finalizeDebugInstrRefs() { auto *TII = getSubtarget().getInstrInfo(); - auto MakeDbgValue = [&](MachineInstr &MI) { + auto MakeUndefDbgValue = [&](MachineInstr &MI) { const MCInstrDesc &RefII = TII->get(TargetOpcode::DBG_VALUE); MI.setDesc(RefII); + MI.getOperand(0).setReg(0); MI.getOperand(1).ChangeToRegister(0, false); }; @@ -1187,15 +1188,15 @@ void MachineFunction::finalizeDebugInstrRefs() { Register Reg = MI.getOperand(0).getReg(); // Some vregs can be deleted as redundant in the meantime. Mark those - // as DBG_VALUE $noreg. - if (Reg == 0) { - MakeDbgValue(MI); + // as DBG_VALUE $noreg. Additionally, some normal instructions are + // quickly deleted, leaving dangling references to vregs with no def. + if (Reg == 0 || !RegInfo->hasOneDef(Reg)) { + MakeUndefDbgValue(MI); continue; } assert(Reg.isVirtual()); MachineInstr &DefMI = *RegInfo->def_instr_begin(Reg); - assert(RegInfo->hasOneDef(Reg)); // If we've found a copy-like instruction, follow it back to the // instruction that defines the source value, see salvageCopySSA docs |