[IRCE] Fix misuse of dyn_cast which leads to UB
authorMax Kazantsev <max.kazantsev@azul.com>
Fri, 4 May 2018 07:34:35 +0000 (07:34 +0000)
committerMax Kazantsev <max.kazantsev@azul.com>
Fri, 4 May 2018 07:34:35 +0000 (07:34 +0000)
llvm-svn: 331508

llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp

index 6d85245..79004dd 100644 (file)
@@ -925,11 +925,12 @@ LoopStructure::parseLoopStructure(ScalarEvolution &SE,
     return None;
   }
   const SCEV* StepRec = IndVarBase->getStepRecurrence(SE);
-  ConstantInt *StepCI = dyn_cast<SCEVConstant>(StepRec)->getValue();
-  if (!StepCI) {
+  if (!isa<SCEVConstant>(StepRec)) {
     FailureReason = "LHS in icmp not induction variable";
     return None;
   }
+  ConstantInt *StepCI = cast<SCEVConstant>(StepRec)->getValue();
+
   if (ICI->isEquality() && !HasNoSignedWrap(IndVarBase)) {
     FailureReason = "LHS in icmp needs nsw for equality predicates";
     return None;