aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnders Carlsson <andersca@mac.com>2008-12-21 03:44:36 +0000
committerAnders Carlsson <andersca@mac.com>2008-12-21 03:44:36 +0000
commit6183a99b064b397d98297904fbd6cf00fe1f453d (patch)
treef38e16a713dceccb5c4cd68cce66cb2340fc65b3
parent0269709723e4cb0836a1a50964949e96dc0d1173 (diff)
Add ASTContext::getBaseElementType and use it in CodeGenFunction::EmitArraySubscriptExpr.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@61303 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--include/clang/AST/ASTContext.h4
-rw-r--r--lib/AST/ASTContext.cpp10
-rw-r--r--lib/CodeGen/CGExpr.cpp7
3 files changed, 15 insertions, 6 deletions
diff --git a/include/clang/AST/ASTContext.h b/include/clang/AST/ASTContext.h
index 4a1992a914..35b48e96f7 100644
--- a/include/clang/AST/ASTContext.h
+++ b/include/clang/AST/ASTContext.h
@@ -433,6 +433,10 @@ public:
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
diff --git a/lib/AST/ASTContext.cpp b/lib/AST/ASTContext.cpp
index 791e38633b..f81d41aa61 100644
--- a/lib/AST/ASTContext.cpp
+++ b/lib/AST/ASTContext.cpp
@@ -1394,6 +1394,16 @@ QualType ASTContext::getArrayDecayedType(QualType Ty) {
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) {
diff --git a/lib/CodeGen/CGExpr.cpp b/lib/CodeGen/CGExpr.cpp
index 3bf6b2f809..18ccb27301 100644
--- a/lib/CodeGen/CGExpr.cpp
+++ b/lib/CodeGen/CGExpr.cpp
@@ -712,12 +712,7 @@ LValue CodeGenFunction::EmitArraySubscriptExpr(const ArraySubscriptExpr *E) {
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,