[llvm] [llvm::transforms] Add overflow check in AllocaInst::getAllocationSize (PR #97170)
Thorsten Schütt via llvm-commits
llvm-commits at lists.llvm.org
Sat Jun 29 12:03:46 PDT 2024
================
@@ -60,22 +61,33 @@ static cl::opt<bool> DisableI2pP2iOpt(
std::optional<TypeSize>
AllocaInst::getAllocationSize(const DataLayout &DL) const {
TypeSize Size = DL.getTypeAllocSize(getAllocatedType());
- if (isArrayAllocation()) {
- auto *C = dyn_cast<ConstantInt>(getArraySize());
- if (!C)
- return std::nullopt;
- assert(!Size.isScalable() && "Array elements cannot have a scalable size");
- Size *= C->getZExtValue();
+ if (!isArrayAllocation()) {
+ return Size;
}
- return Size;
+ auto *C = dyn_cast<ConstantInt>(getArraySize());
+ if (!C)
+ return std::nullopt;
+ assert(!Size.isScalable() && "Array elements cannot have a scalable size");
+ auto checkedProd =
+ checkedMulUnsigned(Size.getKnownMinValue(), C->getZExtValue());
+ if (!checkedProd) {
----------------
tschuett wrote:
Please remove redundant braces.
https://github.com/llvm/llvm-project/pull/97170
More information about the llvm-commits
mailing list