From 62498962e42dc53975e8fea11cb54bce44082649 Mon Sep 17 00:00:00 2001 From: David Stuttard Date: Wed, 23 Nov 2022 15:53:36 +0000 Subject: [PATCH] ConstantFolding: Guard use of getFunction Add additional guards for a use of getFunction on an Instruction In some cases constanfFoldCanonicalize can be called with a cloned instruction that doesn't have a parent (or associated function), causing a seg fault. Differential Revision: https://reviews.llvm.org/D138642 --- llvm/lib/Analysis/ConstantFolding.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/llvm/lib/Analysis/ConstantFolding.cpp b/llvm/lib/Analysis/ConstantFolding.cpp index 690545c..1db9fac 100644 --- a/llvm/lib/Analysis/ConstantFolding.cpp +++ b/llvm/lib/Analysis/ConstantFolding.cpp @@ -1959,7 +1959,7 @@ static Constant *constantFoldCanonicalize(const Type *Ty, const CallBase *CI, if (Src.isNormal() || Src.isInfinity()) return ConstantFP::get(CI->getContext(), Src); - if (Src.isDenormal()) { + if (Src.isDenormal() && CI->getParent() && CI->getFunction()) { DenormalMode DenormMode = CI->getFunction()->getDenormalMode(Src.getSemantics()); if (DenormMode == DenormalMode::getIEEE()) -- 2.7.4