]> granicus.if.org Git - clang/commitdiff
remove the special case for constant array sizes from
authorChris Lattner <sabre@nondot.org>
Tue, 20 Jul 2010 18:45:57 +0000 (18:45 +0000)
committerChris Lattner <sabre@nondot.org>
Tue, 20 Jul 2010 18:45:57 +0000 (18:45 +0000)
EmitCXXNewAllocSize.  This code uses IRBuilder, which does
constant folding already.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@108882 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/CGExprCXX.cpp

index 69e5f0ef4be894ac725a94f62ed471c8ba4b5f2b..7ff452d8c884f0b43d6146ef8b0b95afee09d067 100644 (file)
@@ -420,9 +420,9 @@ static CharUnits CalculateCookiePadding(ASTContext &Ctx, const CXXNewExpr *E) {
 }
 
 static llvm::Value *EmitCXXNewAllocSize(ASTContext &Context,
-                                        CodeGenFunction &CGF, 
+                                        CodeGenFunction &CGF,
                                         const CXXNewExpr *E,
-                                        llvm::Value *& NumElements) {
+                                        llvm::Value *&NumElements) {
   QualType Type = E->getAllocatedType();
   CharUnits TypeSize = CGF.getContext().getTypeSizeInChars(Type);
   const llvm::Type *SizeTy = CGF.ConvertType(CGF.getContext().getSizeType());
@@ -432,28 +432,6 @@ static llvm::Value *EmitCXXNewAllocSize(ASTContext &Context,
 
   CharUnits CookiePadding = CalculateCookiePadding(CGF.getContext(), E);
   
-  Expr::EvalResult Result;
-  if (E->getArraySize()->Evaluate(Result, CGF.getContext()) &&
-      !Result.HasSideEffects && Result.Val.isInt()) {
-
-    CharUnits AllocSize = 
-      Result.Val.getInt().getZExtValue() * TypeSize + CookiePadding;
-    
-    NumElements = 
-      llvm::ConstantInt::get(SizeTy, Result.Val.getInt().getZExtValue());
-    while (const ArrayType *AType = Context.getAsArrayType(Type)) {
-      const llvm::ArrayType *llvmAType =
-        cast<llvm::ArrayType>(CGF.ConvertType(Type));
-      NumElements =
-        CGF.Builder.CreateMul(NumElements, 
-                              llvm::ConstantInt::get(
-                                        SizeTy, llvmAType->getNumElements()));
-      Type = AType->getElementType();
-    }
-    
-    return llvm::ConstantInt::get(SizeTy, AllocSize.getQuantity());
-  }
-  
   // Emit the array size expression.
   NumElements = CGF.EmitScalarExpr(E->getArraySize());