diff options
author | Sanjay Patel <spatel@rotateright.com> | 2021-07-20 18:23:20 -0400 |
---|---|---|
committer | Sanjay Patel <spatel@rotateright.com> | 2021-07-20 18:25:21 -0400 |
commit | 13302c06cdae6b03e56e7e68cd7dea604741352b (patch) | |
tree | 8e78b848923aeeafa70173955ddb9fade25ce738 /llvm/lib/Analysis/ConstantFolding.cpp | |
parent | b43e083bb6b145905cac576b728f238a692a0048 (diff) | |
download | llvm-13302c06cdae6b03e56e7e68cd7dea604741352b.zip llvm-13302c06cdae6b03e56e7e68cd7dea604741352b.tar.gz llvm-13302c06cdae6b03e56e7e68cd7dea604741352b.tar.bz2 |
[ConstantFolding] avoid crashing on a fake math library call
https://llvm.org/PR50960
Diffstat (limited to 'llvm/lib/Analysis/ConstantFolding.cpp')
-rw-r--r-- | llvm/lib/Analysis/ConstantFolding.cpp | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/llvm/lib/Analysis/ConstantFolding.cpp b/llvm/lib/Analysis/ConstantFolding.cpp index 1c6709c..af25dab 100644 --- a/llvm/lib/Analysis/ConstantFolding.cpp +++ b/llvm/lib/Analysis/ConstantFolding.cpp @@ -3041,10 +3041,18 @@ Constant *llvm::ConstantFoldCall(const CallBase *Call, Function *F, return nullptr; if (!F->hasName()) return nullptr; - StringRef Name = F->getName(); - Type *Ty = F->getReturnType(); + // If this is not an intrinsic and not recognized as a library call, bail out. + if (F->getIntrinsicID() == Intrinsic::not_intrinsic) { + if (!TLI) + return nullptr; + LibFunc LibF; + if (!TLI->getLibFunc(*F, LibF)) + return nullptr; + } + StringRef Name = F->getName(); + Type *Ty = F->getReturnType(); if (auto *FVTy = dyn_cast<FixedVectorType>(Ty)) return ConstantFoldFixedVectorCall( Name, F->getIntrinsicID(), FVTy, Operands, @@ -3055,6 +3063,9 @@ Constant *llvm::ConstantFoldCall(const CallBase *Call, Function *F, Name, F->getIntrinsicID(), SVTy, Operands, F->getParent()->getDataLayout(), TLI, Call); + // TODO: If this is a library function, we already discovered that above, + // so we should pass the LibFunc, not the name (and it might be better + // still to separate intrinsic handling from libcalls). return ConstantFoldScalarCall(Name, F->getIntrinsicID(), Ty, Operands, TLI, Call); } |