const IncompleteArrayType *getAsIncompleteArrayType(QualType T) {
return dyn_cast_or_null<IncompleteArrayType>(getAsArrayType(T));
}
+
+ /// getBaseElementType - Returns the innermost element type of a variable
+ /// length array type. For example, will return "int" for int[m][n]
+ QualType getBaseElementType(const VariableArrayType *VAT);
/// getArrayDecayedType - Return the properly qualified result of decaying the
/// specified array type to a pointer. This operation is non-trivial when
return PtrTy.getQualifiedType(PrettyArrayType->getIndexTypeQualifier());
}
+QualType ASTContext::getBaseElementType(const VariableArrayType *VAT)
+{
+ QualType ElemTy = VAT->getElementType();
+
+ if (const VariableArrayType *VAT = getAsVariableArrayType(ElemTy))
+ return getBaseElementType(VAT);
+
+ return ElemTy;
+}
+
/// getFloatingRank - Return a relative rank for floating point types.
/// This routine will assert if passed a built-in type that isn't a float.
static FloatingRank getFloatingRank(QualType T) {
Idx = Builder.CreateMul(Idx, VLASize);
- QualType BaseType = VAT->getElementType();
-
- // Divide by the element size.
- while (const VariableArrayType *AT =
- getContext().getAsVariableArrayType(BaseType))
- BaseType = AT->getElementType();
+ QualType BaseType = getContext().getBaseElementType(VAT);
uint64_t BaseTypeSize = getContext().getTypeSize(BaseType) / 8;
Idx = Builder.CreateUDiv(Idx,