Skip to content

Commit a313c87

Browse files
committed
CodeGenPrepare: Null check pointers
1 parent 61d3ad9 commit a313c87

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

llvm/lib/CodeGen/CodeGenPrepare.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -559,6 +559,7 @@ PreservedAnalyses CodeGenPreparePass::run(Function &F,
559559
}
560560

561561
bool CodeGenPrepare::run(Function &F, FunctionAnalysisManager &AM) {
562+
assert(TM && "TargetMachine is required for CodeGenPrepare");
562563
DL = &F.getDataLayout();
563564
SubtargetInfo = TM->getSubtargetImpl(F);
564565
TLI = SubtargetInfo->getTargetLowering();
@@ -589,16 +590,16 @@ bool CodeGenPrepare::_run(Function &F) {
589590
// counts based hotness overwrite the cold attribute.
590591
// This is a conservative behabvior.
591592
if (F.hasFnAttribute(Attribute::Hot) ||
592-
PSI->isFunctionHotInCallGraph(&F, *BFI))
593+
(PSI && PSI->isFunctionHotInCallGraph(&F, *BFI)))
593594
F.setSectionPrefix("hot");
594595
// If PSI shows this function is not hot, we will placed the function
595596
// into unlikely section if (1) PSI shows this is a cold function, or
596597
// (2) the function has a attribute of cold.
597-
else if (PSI->isFunctionColdInCallGraph(&F, *BFI) ||
598+
else if ((PSI && PSI->isFunctionColdInCallGraph(&F, *BFI)) ||
598599
F.hasFnAttribute(Attribute::Cold))
599600
F.setSectionPrefix("unlikely");
600-
else if (ProfileUnknownInSpecialSection && PSI->hasPartialSampleProfile() &&
601-
PSI->isFunctionHotnessUnknown(F))
601+
else if (ProfileUnknownInSpecialSection && PSI &&
602+
PSI->hasPartialSampleProfile() && PSI->isFunctionHotnessUnknown(F))
602603
F.setSectionPrefix("unknown");
603604
}
604605

0 commit comments

Comments
 (0)