From 781beb3de5a898107c28b74c1a228d86c6eed19e Mon Sep 17 00:00:00 2001 From: Nikita Popov Date: Thu, 20 Jul 2023 14:49:08 +0200 Subject: [PATCH] [LVI] Check ConstantFoldCompareInstOperands() failure (NFCI) I don't believe this can happen right now (because we're only working on icmps and as such can't hit the current fcmp null paths), but this will be possible in the future when icmp constant expressions are removed. --- llvm/lib/Analysis/LazyValueInfo.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/llvm/lib/Analysis/LazyValueInfo.cpp b/llvm/lib/Analysis/LazyValueInfo.cpp index 7a40259..3365178 100644 --- a/llvm/lib/Analysis/LazyValueInfo.cpp +++ b/llvm/lib/Analysis/LazyValueInfo.cpp @@ -1749,7 +1749,7 @@ getPredicateResult(unsigned Pred, Constant *C, const ValueLatticeElement &Val, Constant *Res = nullptr; if (Val.isConstant()) { Res = ConstantFoldCompareInstOperands(Pred, Val.getConstant(), C, DL, TLI); - if (ConstantInt *ResCI = dyn_cast(Res)) + if (ConstantInt *ResCI = dyn_cast_or_null(Res)) return ResCI->isZero() ? LazyValueInfo::False : LazyValueInfo::True; return LazyValueInfo::Unknown; } @@ -1791,14 +1791,14 @@ getPredicateResult(unsigned Pred, Constant *C, const ValueLatticeElement &Val, Res = ConstantFoldCompareInstOperands(ICmpInst::ICMP_NE, Val.getNotConstant(), C, DL, TLI); - if (Res->isNullValue()) + if (Res && Res->isNullValue()) return LazyValueInfo::False; } else if (Pred == ICmpInst::ICMP_NE) { // !C1 != C -> true iff C1 == C. Res = ConstantFoldCompareInstOperands(ICmpInst::ICMP_NE, Val.getNotConstant(), C, DL, TLI); - if (Res->isNullValue()) + if (Res && Res->isNullValue()) return LazyValueInfo::True; } return LazyValueInfo::Unknown; -- 2.7.4