From c41aa41957c102fdbe1e92c31fd1aec1c5fccbd5 Mon Sep 17 00:00:00 2001 From: Nikita Popov Date: Thu, 6 Jan 2022 09:58:31 +0100 Subject: [ConstFold] Add missing check for inbounds gep If the gep is not inbounds, then the gep might compute a null value even if the base pointer is non-null. --- llvm/lib/IR/ConstantFold.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'llvm/lib/IR/ConstantFold.cpp') diff --git a/llvm/lib/IR/ConstantFold.cpp b/llvm/lib/IR/ConstantFold.cpp index 0d76dd7..9f1d76b 100644 --- a/llvm/lib/IR/ConstantFold.cpp +++ b/llvm/lib/IR/ConstantFold.cpp @@ -1537,7 +1537,7 @@ static ICmpInst::Predicate evaluateICmpRelation(Constant *V1, Constant *V2, if (const GlobalValue *GV = dyn_cast(CE1Op0)) { // If its not weak linkage, the GVal must have a non-zero address // so the result is greater-than - if (!GV->hasExternalWeakLinkage()) + if (!GV->hasExternalWeakLinkage() && CE1GEP->isInBounds()) return ICmpInst::ICMP_UGT; } } else if (const GlobalValue *GV2 = dyn_cast(V2)) { -- cgit v1.1