]> granicus.if.org Git - clang/commitdiff
simplify code and smallvectorize.
authorChris Lattner <sabre@nondot.org>
Mon, 6 Feb 2012 22:00:56 +0000 (22:00 +0000)
committerChris Lattner <sabre@nondot.org>
Mon, 6 Feb 2012 22:00:56 +0000 (22:00 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@149915 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/CGExprConstant.cpp

index aa21bd37bdd9649306d433b5a0df9a3c296582aa..b3bb0cc2072efe1b70faf5e86f3f977b75375658 100644 (file)
@@ -1375,17 +1375,18 @@ llvm::Constant *CodeGenModule::EmitNullConstant(QualType T) {
     return llvm::Constant::getNullValue(getTypes().ConvertTypeForMem(T));
     
   if (const ConstantArrayType *CAT = Context.getAsConstantArrayType(T)) {
+    llvm::ArrayType *ATy =
+      cast<llvm::ArrayType>(getTypes().ConvertTypeForMem(T));
 
     QualType ElementTy = CAT->getElementType();
 
     llvm::Constant *Element = EmitNullConstant(ElementTy);
     unsigned NumElements = CAT->getSize().getZExtValue();
-    std::vector<llvm::Constant *> Array(NumElements);
-    for (unsigned i = 0; i != NumElements; ++i)
-      Array[i] = Element;
-
-    llvm::ArrayType *ATy =
-      cast<llvm::ArrayType>(getTypes().ConvertTypeForMem(T));
+    
+    if (Element->isNullValue())
+      return llvm::ConstantAggregateZero::get(ATy);
+    
+    SmallVector<llvm::Constant *, 8> Array(NumElements, Element);
     return llvm::ConstantArray::get(ATy, Array);
   }