From a313c87fe132fc576304a7334ee7153acfb5433a Mon Sep 17 00:00:00 2001 From: Akshat Oke Date: Mon, 2 Jun 2025 09:00:13 +0000 Subject: CodeGenPrepare: Null check pointers --- llvm/lib/CodeGen/CodeGenPrepare.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'llvm/lib/CodeGen/CodeGenPrepare.cpp') diff --git a/llvm/lib/CodeGen/CodeGenPrepare.cpp b/llvm/lib/CodeGen/CodeGenPrepare.cpp index 76f27623c865..a191dce96be2 100644 --- a/llvm/lib/CodeGen/CodeGenPrepare.cpp +++ b/llvm/lib/CodeGen/CodeGenPrepare.cpp @@ -559,6 +559,7 @@ PreservedAnalyses CodeGenPreparePass::run(Function &F, } bool CodeGenPrepare::run(Function &F, FunctionAnalysisManager &AM) { + assert(TM && "TargetMachine is required for CodeGenPrepare"); DL = &F.getDataLayout(); SubtargetInfo = TM->getSubtargetImpl(F); TLI = SubtargetInfo->getTargetLowering(); @@ -589,16 +590,16 @@ bool CodeGenPrepare::_run(Function &F) { // counts based hotness overwrite the cold attribute. // This is a conservative behabvior. if (F.hasFnAttribute(Attribute::Hot) || - PSI->isFunctionHotInCallGraph(&F, *BFI)) + (PSI && PSI->isFunctionHotInCallGraph(&F, *BFI))) F.setSectionPrefix("hot"); // If PSI shows this function is not hot, we will placed the function // into unlikely section if (1) PSI shows this is a cold function, or // (2) the function has a attribute of cold. - else if (PSI->isFunctionColdInCallGraph(&F, *BFI) || + else if ((PSI && PSI->isFunctionColdInCallGraph(&F, *BFI)) || F.hasFnAttribute(Attribute::Cold)) F.setSectionPrefix("unlikely"); - else if (ProfileUnknownInSpecialSection && PSI->hasPartialSampleProfile() && - PSI->isFunctionHotnessUnknown(F)) + else if (ProfileUnknownInSpecialSection && PSI && + PSI->hasPartialSampleProfile() && PSI->isFunctionHotnessUnknown(F)) F.setSectionPrefix("unknown"); } -- cgit v1.2.3