aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/CodeGen/LiveDebugValues.cpp
diff options
context:
space:
mode:
authorVedant Kumar <vsk@apple.com>2020-03-03 11:08:48 -0800
committerVedant Kumar <vsk@apple.com>2020-03-03 13:00:52 -0800
commit2bf496620cbb52f918b24bfa4283f5712fb3b937 (patch)
tree5d4086450c775b858296c705935ad11eb7ccc3c2 /llvm/lib/CodeGen/LiveDebugValues.cpp
parente70a9f3850255cb610fc56a30dec6f52b9d734e9 (diff)
downloadllvm-2bf496620cbb52f918b24bfa4283f5712fb3b937.zip
llvm-2bf496620cbb52f918b24bfa4283f5712fb3b937.tar.gz
llvm-2bf496620cbb52f918b24bfa4283f5712fb3b937.tar.bz2
[LiveDebugValues] Do not insert DBG_VALUEs after a MBB terminator
This fixes a miscompile that happened because a DBG_VALUE interfered with the MachineOutliner's liveness analysis. Inserting a DBG_VALUE after a terminator breaks predicates on MBB such as isReturnBlock(). And the resulting DBG_VALUE cannot be "live". I plan to introduce a MachineVerifier check for this situation in a follow up. rdar://59859175 Testing: check-llvm, LNT build with a stage2 compiler & entry values enabled Differential Revision: https://reviews.llvm.org/D75548
Diffstat (limited to 'llvm/lib/CodeGen/LiveDebugValues.cpp')
-rw-r--r--llvm/lib/CodeGen/LiveDebugValues.cpp7
1 files changed, 7 insertions, 0 deletions
diff --git a/llvm/lib/CodeGen/LiveDebugValues.cpp b/llvm/lib/CodeGen/LiveDebugValues.cpp
index 4d0c246..94c5cc5 100644
--- a/llvm/lib/CodeGen/LiveDebugValues.cpp
+++ b/llvm/lib/CodeGen/LiveDebugValues.cpp
@@ -959,6 +959,10 @@ void LiveDebugValues::emitEntryValues(MachineInstr &MI,
VarLocMap &VarLocIDs,
TransferMap &Transfers,
VarLocSet &KillSet) {
+ // Do not insert entry value locations after a terminator.
+ if (MI.isTerminator())
+ return;
+
for (uint64_t ID : KillSet) {
LocIndex Idx = LocIndex::fromRawInteger(ID);
const VarLoc &VL = VarLocIDs[Idx];
@@ -1003,6 +1007,7 @@ void LiveDebugValues::insertTransferDebugPair(
// Record the new location as an open range, and a postponed transfer
// inserting a DBG_VALUE for this location.
OpenRanges.insert(LocId, VL);
+ assert(!MI.isTerminator() && "Cannot insert DBG_VALUE after terminator");
TransferDebugPair MIP = {&MI, LocId};
Transfers.push_back(MIP);
};
@@ -1778,6 +1783,8 @@ bool LiveDebugValues::ExtendRanges(MachineFunction &MF) {
// Add any DBG_VALUE instructions created by location transfers.
for (auto &TR : Transfers) {
+ assert(!TR.TransferInst->isTerminator() &&
+ "Cannot insert DBG_VALUE after terminator");
MachineBasicBlock *MBB = TR.TransferInst->getParent();
const VarLoc &VL = VarLocIDs[TR.LocationID];
MachineInstr *MI = VL.BuildDbgValue(MF);