diff options
author | Anders Carlsson <andersca@mac.com> | 2008-12-21 00:11:23 +0000 |
---|---|---|
committer | Anders Carlsson <andersca@mac.com> | 2008-12-21 00:11:23 +0000 |
commit | 3d312f87881139339ea6f1f6977954791478f047 (patch) | |
tree | d6bfa97152efb0191d08e44e51a347ca603becf9 /clang/lib/CodeGen/CGExpr.cpp | |
parent | 2eedc3aa1ce4af390e5f1efd49087fd23f191565 (diff) | |
download | bcm5719-llvm-3d312f87881139339ea6f1f6977954791478f047.tar.gz bcm5719-llvm-3d312f87881139339ea6f1f6977954791478f047.zip |
Handle VLA indexing
llvm-svn: 61295
Diffstat (limited to 'clang/lib/CodeGen/CGExpr.cpp')
-rw-r--r-- | clang/lib/CodeGen/CGExpr.cpp | 21 |
1 files changed, 19 insertions, 2 deletions
diff --git a/clang/lib/CodeGen/CGExpr.cpp b/clang/lib/CodeGen/CGExpr.cpp index b085de304aa..3bf6b2f8091 100644 --- a/clang/lib/CodeGen/CGExpr.cpp +++ b/clang/lib/CodeGen/CGExpr.cpp @@ -706,8 +706,25 @@ LValue CodeGenFunction::EmitArraySubscriptExpr(const ArraySubscriptExpr *E) { // We know that the pointer points to a type of the correct size, unless the // size is a VLA. - if (!E->getType()->isConstantSizeType()) - return EmitUnsupportedLValue(E, "VLA index"); + if (const VariableArrayType *VAT = + getContext().getAsVariableArrayType(E->getType())) { + llvm::Value *VLASize = VLASizeMap[VAT]; + + Idx = Builder.CreateMul(Idx, VLASize); + + QualType BaseType = VAT->getElementType(); + + // Divide by the element size. + while (const VariableArrayType *AT = + getContext().getAsVariableArrayType(BaseType)) + BaseType = AT->getElementType(); + + uint64_t BaseTypeSize = getContext().getTypeSize(BaseType) / 8; + Idx = Builder.CreateUDiv(Idx, + llvm::ConstantInt::get(Idx->getType(), + BaseTypeSize)); + } + QualType ExprTy = getContext().getCanonicalType(E->getBase()->getType()); return LValue::MakeAddr(Builder.CreateGEP(Base, Idx, "arrayidx"), |