summaryrefslogtreecommitdiff
path: root/lib/CodeGen/CGExpr.cpp
diff options
context:
space:
mode:
authorAnders Carlsson <andersca@mac.com>2008-12-21 00:11:23 +0000
committerAnders Carlsson <andersca@mac.com>2008-12-21 00:11:23 +0000
commit8b33c087fc6d97064b6620c96c732ebc5c003fb2 (patch)
treeb11032be775639fd18541f6ccd48801c9bb462e0 /lib/CodeGen/CGExpr.cpp
parent86f194083504938df72135b5b66bf0c5cafd9498 (diff)
downloadclang-8b33c087fc6d97064b6620c96c732ebc5c003fb2.tar.gz
clang-8b33c087fc6d97064b6620c96c732ebc5c003fb2.tar.bz2
clang-8b33c087fc6d97064b6620c96c732ebc5c003fb2.tar.xz
Handle VLA indexing
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@61295 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/CodeGen/CGExpr.cpp')
-rw-r--r--lib/CodeGen/CGExpr.cpp21
1 files changed, 19 insertions, 2 deletions
diff --git a/lib/CodeGen/CGExpr.cpp b/lib/CodeGen/CGExpr.cpp
index b085de304a..3bf6b2f809 100644
--- a/lib/CodeGen/CGExpr.cpp
+++ b/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"),