There are two bugs in computing size allocated by an array alloca:
- For primitive types, it computes the number of bits and there is a FIXME
- For aggregate types, the computed size is always 0.
The fix is to use DL.getTypeAllocSize(Ty) as it is done for static alloca
The addition can overflow as well.
Maybe use SaturatingMultiplyAdd from MathExtras.h instead of APInt?