]> granicus.if.org Git - llvm/commitdiff
InstrProf - avoid static analyzer dyn_cast<ConstantInt> null dereference warning.
authorSimon Pilgrim <llvm-dev@redking.me.uk>
Tue, 1 Oct 2019 10:38:30 +0000 (10:38 +0000)
committerSimon Pilgrim <llvm-dev@redking.me.uk>
Tue, 1 Oct 2019 10:38:30 +0000 (10:38 +0000)
The static analyzer is warning about a potential null dereference, as we're already earlying-out for a null Constant pointer I've just folded this into a dyn_cast_or_null<ConstantInt>.

No test case, this is by inspection only.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@373322 91177308-0d34-0410-b5e6-96231b3b80d8

lib/ProfileData/InstrProf.cpp

index 510fd9887d9a359a4e8525044b4b485ad981f870..8cad6861b33ac60f78e936fa1377c4ba23b489ae 100644 (file)
@@ -1078,12 +1078,10 @@ bool isIRPGOFlagSet(const Module *M) {
   if (!IRInstrVar->hasInitializer())
     return false;
 
-  const Constant *InitVal = IRInstrVar->getInitializer();
+  auto *InitVal = dyn_cast_or_null<ConstantInt>(IRInstrVar->getInitializer());
   if (!InitVal)
     return false;
-
-  return (dyn_cast<ConstantInt>(InitVal)->getZExtValue() &
-          VARIANT_MASK_IR_PROF) != 0;
+  return (InitVal->getZExtValue() & VARIANT_MASK_IR_PROF) != 0;
 }
 
 // Check if we can safely rename this Comdat function.