- // Type must be known to determine array size.
- const Type* T = getMallocAllocatedType(CI);
- if (!T)
- return NULL;
-
- Value* MallocArg = CI->getOperand(1);
- ConstantExpr* CO = dyn_cast<ConstantExpr>(MallocArg);
- BinaryOperator* BO = dyn_cast<BinaryOperator>(MallocArg);
-
- Constant* ElementSize = ConstantExpr::getSizeOf(T);
- ElementSize = ConstantExpr::getTruncOrBitCast(ElementSize,
- MallocArg->getType());
- Constant *FoldedElementSize =
- ConstantFoldConstantExpression(cast<ConstantExpr>(ElementSize), Context, TD);
-
- // First, check if CI is a non-array malloc.
- if (CO && ((CO == ElementSize) ||
- (FoldedElementSize && (CO == FoldedElementSize))))
- // Match CreateMalloc's use of constant 1 array-size for non-array mallocs.
- return ConstantInt::get(MallocArg->getType(), 1);
-
- // Second, check if CI is an array malloc whose array size can be determined.
- if (isConstantOne(ElementSize) ||
- (FoldedElementSize && isConstantOne(FoldedElementSize)))
- return MallocArg;
-
- if (!CO && !BO)
+ // The size of the malloc's result type must be known to determine array size.
+ Type *T = getMallocAllocatedType(CI);
+ if (!T || !T->isSized() || !TD)