]> granicus.if.org Git - clang/commitdiff
Add ASTContext::getBaseElementType and use it in CodeGenFunction::EmitArraySubscriptExpr.
authorAnders Carlsson <andersca@mac.com>
Sun, 21 Dec 2008 03:44:36 +0000 (03:44 +0000)
committerAnders Carlsson <andersca@mac.com>
Sun, 21 Dec 2008 03:44:36 +0000 (03:44 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@61303 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/AST/ASTContext.h
lib/AST/ASTContext.cpp
lib/CodeGen/CGExpr.cpp

index 4a1992a914f8650ecac106420b64ca60aaac5274..35b48e96f705dd10f06f522fbebb6a2a6a8ffada 100644 (file)
@@ -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
index 791e38633b44a64faf77cb59f8613512eb024a2c..f81d41aa61f2df3e2c3d7f159f01ab2adc8facaf 100644 (file)
@@ -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) {
index 3bf6b2f8091f66fe8a6ef96a1e9f3ec54afb72da..18ccb27301f9f5de15fa879a7787d953b0b7ca2c 100644 (file)
@@ -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,