From 22e596e986511b6f7a4ef2ffbd7d6fefe5d02607 Mon Sep 17 00:00:00 2001 From: David Green Date: Wed, 23 Aug 2023 11:49:36 +0100 Subject: [PATCH] [AArch64] Fix debug printing crash in AArch64RedundantCopyElimination The LastChange can be MBB->end(), so it is not valid to dereference it for printing. Fix the DEBUG statement to check for end() and handle it specially. --- llvm/lib/Target/AArch64/AArch64RedundantCopyElimination.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/llvm/lib/Target/AArch64/AArch64RedundantCopyElimination.cpp b/llvm/lib/Target/AArch64/AArch64RedundantCopyElimination.cpp index 369801a8ea7c..1494312886a4 100644 --- a/llvm/lib/Target/AArch64/AArch64RedundantCopyElimination.cpp +++ b/llvm/lib/Target/AArch64/AArch64RedundantCopyElimination.cpp @@ -462,7 +462,9 @@ bool AArch64RedundantCopyElimination::optimizeBlock(MachineBasicBlock *MBB) { // Clear kills in the range where changes were made. This is conservative, // but should be okay since kill markers are being phased out. LLVM_DEBUG(dbgs() << "Clearing kill flags.\n\tFirstUse: " << *FirstUse - << "\tLastChange: " << *LastChange); + << "\tLastChange: "; + if (LastChange == MBB->end()) dbgs() << "\n"; + else dbgs() << *LastChange); for (MachineInstr &MMI : make_range(FirstUse, PredMBB->end())) MMI.clearKillInfo(); for (MachineInstr &MMI : make_range(MBB->begin(), LastChange))