]> granicus.if.org Git - clang/commitdiff
Follow Eli's advice and store the VLA size with the native size_t type. Fixes PR3491.
authorAnders Carlsson <andersca@mac.com>
Thu, 5 Feb 2009 19:43:10 +0000 (19:43 +0000)
committerAnders Carlsson <andersca@mac.com>
Thu, 5 Feb 2009 19:43:10 +0000 (19:43 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@63879 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/CGDecl.cpp
lib/CodeGen/CGExprScalar.cpp
lib/CodeGen/CodeGenFunction.cpp

index 898c1bfd80db39210f9796442a557de70389af7e..73d3e2103c1f69c2ee649b74e3d287d6a774f4cc 100644 (file)
@@ -197,6 +197,9 @@ void CodeGenFunction::EmitLocalBlockVarDecl(const VarDecl &D) {
 
     llvm::Value *VLASize = EmitVLASize(Ty);
 
+    // Downcast the VLA size expression
+    VLASize = Builder.CreateIntCast(VLASize, llvm::Type::Int32Ty, false, "tmp");
+    
     // Allocate memory for the array.
     llvm::Value *VLA = Builder.CreateAlloca(llvm::Type::Int8Ty, VLASize, "vla");
     DeclPtr = Builder.CreateBitCast(VLA, LElemPtrTy, "tmp");
index 44eefea71dbd09fac1657ce63dd2beaffcc73685..b9dcc078d4dbea0a2a4bd2c2c60125a335a49389 100644 (file)
@@ -685,9 +685,7 @@ ScalarExprEmitter::VisitSizeOfAlignOfExpr(const SizeOfAlignOfExpr *E) {
         CGF.EmitVLASize(TypeToSize);
       }
       
-      llvm::Value *VLASize = CGF.GetVLASize(VAT);
-      return Builder.CreateIntCast(VLASize, ConvertType(E->getType()), 
-                                   false, "conv");
+      return CGF.GetVLASize(VAT);
     }
   }
 
index 58559e5249641fdf1593366a50c7ec084afac582..2b365c9ccab560cfb9928a7c41d8880e0b5ed456 100644 (file)
@@ -480,18 +480,19 @@ llvm::Value *CodeGenFunction::EmitVLASize(QualType Ty)
       llvm::Value *ElemSize;
     
       QualType ElemTy = VAT->getElementType();
-    
+
+      const llvm::Type *SizeTy = ConvertType(getContext().getSizeType());
+                                             
       if (ElemTy->isVariableArrayType())
         ElemSize = EmitVLASize(ElemTy);
       else {
-        // FIXME: We use Int32Ty here because the alloca instruction takes a
-        // 32-bit integer. What should we do about overflow?
-        ElemSize = llvm::ConstantInt::get(llvm::Type::Int32Ty, 
+        ElemSize = llvm::ConstantInt::get(SizeTy,
                                           getContext().getTypeSize(ElemTy) / 8);
       }
     
       llvm::Value *NumElements = EmitScalarExpr(VAT->getSizeExpr());
-    
+      NumElements = Builder.CreateIntCast(NumElements, SizeTy, false, "tmp");
+      
       SizeEntry = Builder.CreateMul(ElemSize, NumElements);
     }