[cfe-commits] r61303 - in /cfe/trunk: include/clang/AST/ASTContext.h lib/AST/ASTContext.cpp lib/CodeGen/CGExpr.cpp

Anders Carlsson andersca at mac.com
Sat Dec 20 19:44:37 PST 2008


Author: andersca
Date: Sat Dec 20 21:44:36 2008
New Revision: 61303

URL: http://llvm.org/viewvc/llvm-project?rev=61303&view=rev
Log:
Add ASTContext::getBaseElementType and use it in CodeGenFunction::EmitArraySubscriptExpr.

Modified:
    cfe/trunk/include/clang/AST/ASTContext.h
    cfe/trunk/lib/AST/ASTContext.cpp
    cfe/trunk/lib/CodeGen/CGExpr.cpp

Modified: cfe/trunk/include/clang/AST/ASTContext.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/ASTContext.h?rev=61303&r1=61302&r2=61303&view=diff

==============================================================================
--- cfe/trunk/include/clang/AST/ASTContext.h (original)
+++ cfe/trunk/include/clang/AST/ASTContext.h Sat Dec 20 21:44:36 2008
@@ -433,6 +433,10 @@
   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

Modified: cfe/trunk/lib/AST/ASTContext.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ASTContext.cpp?rev=61303&r1=61302&r2=61303&view=diff

==============================================================================
--- cfe/trunk/lib/AST/ASTContext.cpp (original)
+++ cfe/trunk/lib/AST/ASTContext.cpp Sat Dec 20 21:44:36 2008
@@ -1394,6 +1394,16 @@
   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) {

Modified: cfe/trunk/lib/CodeGen/CGExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExpr.cpp?rev=61303&r1=61302&r2=61303&view=diff

==============================================================================
--- cfe/trunk/lib/CodeGen/CGExpr.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGExpr.cpp Sat Dec 20 21:44:36 2008
@@ -712,12 +712,7 @@
     
     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,





More information about the cfe-commits mailing list