From bce3cca4889a9e4ab7b9652b0c44bb49ca8f3bad Mon Sep 17 00:00:00 2001 From: Matt Arsenault Date: Mon, 10 May 2021 20:56:24 -0400 Subject: [PATCH] CodeGen: Fix null dereference before null check --- llvm/lib/CodeGen/MachineBlockFrequencyInfo.cpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/llvm/lib/CodeGen/MachineBlockFrequencyInfo.cpp b/llvm/lib/CodeGen/MachineBlockFrequencyInfo.cpp index 0368583fa235..c569f0350366 100644 --- a/llvm/lib/CodeGen/MachineBlockFrequencyInfo.cpp +++ b/llvm/lib/CodeGen/MachineBlockFrequencyInfo.cpp @@ -233,14 +233,20 @@ MachineBlockFrequencyInfo::getBlockFreq(const MachineBasicBlock *MBB) const { Optional MachineBlockFrequencyInfo::getBlockProfileCount( const MachineBasicBlock *MBB) const { + if (!MBFI) + return None; + const Function &F = MBFI->getFunction()->getFunction(); - return MBFI ? MBFI->getBlockProfileCount(F, MBB) : None; + return MBFI->getBlockProfileCount(F, MBB); } Optional MachineBlockFrequencyInfo::getProfileCountFromFreq(uint64_t Freq) const { + if (!MBFI) + return None; + const Function &F = MBFI->getFunction()->getFunction(); - return MBFI ? MBFI->getProfileCountFromFreq(F, Freq) : None; + return MBFI->getProfileCountFromFreq(F, Freq); } bool MachineBlockFrequencyInfo::isIrrLoopHeader(