[llvm] bce3cca - CodeGen: Fix null dereference before null check

Matt Arsenault via llvm-commits llvm-commits at lists.llvm.org
Tue May 11 06:07:39 PDT 2021


Author: Matt Arsenault
Date: 2021-05-11T09:07:32-04:00
New Revision: bce3cca4889a9e4ab7b9652b0c44bb49ca8f3bad

URL: https://github.com/llvm/llvm-project/commit/bce3cca4889a9e4ab7b9652b0c44bb49ca8f3bad
DIFF: https://github.com/llvm/llvm-project/commit/bce3cca4889a9e4ab7b9652b0c44bb49ca8f3bad.diff

LOG: CodeGen: Fix null dereference before null check

Added: 
    

Modified: 
    llvm/lib/CodeGen/MachineBlockFrequencyInfo.cpp

Removed: 
    


################################################################################
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<uint64_t> 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<uint64_t>
 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(


        


More information about the llvm-commits mailing list