assert (0 && "Cannnot unique VariableArrayTypes.");
}
+ /// Returns the innermost element type of a VAT - for example
+ /// will return "int" for int[n][m].
+ QualType getBaseType() const;
+
protected:
virtual void EmitImpl(llvm::Serializer& S) const;
static Type* CreateImpl(ASTContext& Context,llvm::Deserializer& D);
return isa<EnumDecl>(TT->getDecl());
}
-
//===----------------------------------------------------------------------===//
// Type Printing
//===----------------------------------------------------------------------===//
// 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"),