diff options
author | Alon Zakai <alonzakai@gmail.com> | 2013-11-28 13:53:05 -0800 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2013-11-28 13:53:05 -0800 |
commit | 78448868e56001cbdb78c930c55abf68f2167cd3 (patch) | |
tree | c531759093dac4d5f95a4a909be3e2ddbb7fc964 /lib/Target/CppBackend/CPPBackend.cpp | |
parent | f7b40c2e58d9956e85b6b023129c32296026e6a1 (diff) |
fix alloca
Diffstat (limited to 'lib/Target/CppBackend/CPPBackend.cpp')
-rw-r--r-- | lib/Target/CppBackend/CPPBackend.cpp | 17 |
1 files changed, 10 insertions, 7 deletions
diff --git a/lib/Target/CppBackend/CPPBackend.cpp b/lib/Target/CppBackend/CPPBackend.cpp index b4f84f4fd7..f990ebdc1e 100644 --- a/lib/Target/CppBackend/CPPBackend.cpp +++ b/lib/Target/CppBackend/CPPBackend.cpp @@ -1491,15 +1491,18 @@ std::string CppWriter::generateInstruction(const Instruction *I) { break; } case Instruction::Alloca: { - const AllocaInst* allocaI = cast<AllocaInst>(I); - Type *t = allocaI->getAllocatedType(); - unsigned size; - if (ArrayType *AT = dyn_cast<ArrayType>(t)) { - size = AT->getElementType()->getScalarSizeInBits()/8 * AT->getNumElements(); + const AllocaInst* AI = cast<AllocaInst>(I); + Type *T = AI->getAllocatedType(); + assert(!isa<ArrayType>(T)); + const Value *AS = AI->getArraySize(); + unsigned Size = T->getScalarSizeInBits()/8; + if (const ConstantInt *CI = dyn_cast<ConstantInt>(AS)) { + Size *= CI->getZExtValue(); } else { - size = t->getScalarSizeInBits()/8; + dumpIR(I); + assert(0); } - text = getAssign(iName, Type::getInt32Ty(I->getContext())) + "STACKTOP; STACKTOP = STACKTOP + " + Twine(memAlign(size)).str() + "|0;"; + text = getAssign(iName, Type::getInt32Ty(I->getContext())) + "STACKTOP; STACKTOP = STACKTOP + " + Twine(memAlign(Size)).str() + "|0;"; break; } case Instruction::Load: { |