[llvm] b556ce3 - [IR] adjust assert when replacing undef elements in vector constant
Sanjay Patel via llvm-commits
llvm-commits at lists.llvm.org
Mon Nov 4 07:05:30 PST 2019
Author: Sanjay Patel
Date: 2019-11-04T10:05:24-05:00
New Revision: b556ce3992709e1f6302ca1d4c296f57e83cd6a7
URL: https://github.com/llvm/llvm-project/commit/b556ce3992709e1f6302ca1d4c296f57e83cd6a7
DIFF: https://github.com/llvm/llvm-project/commit/b556ce3992709e1f6302ca1d4c296f57e83cd6a7.diff
LOG: [IR] adjust assert when replacing undef elements in vector constant
As noted in follow-up to:
rGa1e8ad4f2fa7
It's not safe to assume that an element of the constant is always
non-null. It's definitely not an expected case for the current
instcombine user, but that may not hold if this function is
eventually called from arbitrary places.
Added:
Modified:
llvm/lib/IR/Constants.cpp
Removed:
################################################################################
diff --git a/llvm/lib/IR/Constants.cpp b/llvm/lib/IR/Constants.cpp
index eb40b291b005..a6a8eaac2f94 100644
--- a/llvm/lib/IR/Constants.cpp
+++ b/llvm/lib/IR/Constants.cpp
@@ -611,7 +611,7 @@ Constant *Constant::replaceUndefsWith(Constant *C, Constant *Replacement) {
SmallVector<Constant *, 32> NewC(NumElts);
for (unsigned i = 0; i != NumElts; ++i) {
Constant *EltC = C->getAggregateElement(i);
- assert(EltC->getType() == Replacement->getType() &&
+ assert((!EltC || EltC->getType() == Replacement->getType()) &&
"Expected matching types");
NewC[i] = EltC && match(EltC, m_Undef()) ? Replacement : EltC;
}
More information about the llvm-commits
mailing list