[llvm] 6249896 - ConstantFolding: Guard use of getFunction

David Stuttard via llvm-commits llvm-commits at lists.llvm.org
Wed Nov 30 06:13:28 PST 2022


Author: David Stuttard
Date: 2022-11-30T14:09:40Z
New Revision: 62498962e42dc53975e8fea11cb54bce44082649

URL: https://github.com/llvm/llvm-project/commit/62498962e42dc53975e8fea11cb54bce44082649
DIFF: https://github.com/llvm/llvm-project/commit/62498962e42dc53975e8fea11cb54bce44082649.diff

LOG: 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

Added: 
    

Modified: 
    llvm/lib/Analysis/ConstantFolding.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Analysis/ConstantFolding.cpp b/llvm/lib/Analysis/ConstantFolding.cpp
index 690545c0a9d33..1db9faca9e46d 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())


        


More information about the llvm-commits mailing list