[cfe-commits] r51769 - in /cfe/trunk: lib/CodeGen/CGExprConstant.cpp test/CodeGen/vector.c

Eli Friedman eli.friedman at gmail.com
Fri May 30 05:02:14 PDT 2008


Author: efriedma
Date: Fri May 30 07:02:14 2008
New Revision: 51769

URL: http://llvm.org/viewvc/llvm-project?rev=51769&view=rev
Log:
Fix constant vector init for initializer lists with an incomplete list 
of elements.


Modified:
    cfe/trunk/lib/CodeGen/CGExprConstant.cpp
    cfe/trunk/test/CodeGen/vector.c

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

==============================================================================
--- cfe/trunk/lib/CodeGen/CGExprConstant.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGExprConstant.cpp Fri May 30 07:02:14 2008
@@ -242,20 +242,23 @@
   llvm::Constant *EmitVectorInitialization(InitListExpr *ILE) {
     const llvm::VectorType *VType =
         cast<llvm::VectorType>(ConvertType(ILE->getType()));
-    std::vector<llvm::Constant*> Elts;    
-    unsigned NumInitElements = ILE->getNumInits();      
+    const llvm::Type *ElemTy = VType->getElementType();
+    std::vector<llvm::Constant*> Elts;
     unsigned NumElements = VType->getNumElements();
+    unsigned NumInitElements = ILE->getNumInits();
+
+    unsigned NumInitableElts = std::min(NumInitElements, NumElements);
 
-    // FIXME: Handle case in assertion correctly
-    assert (NumInitElements == NumElements 
-            && "Unsufficient vector init elelments");
     // Copy initializer elements.
     unsigned i = 0;
-    for (; i < NumElements; ++i) {
+    for (; i < NumInitableElts; ++i) {
       llvm::Constant *C = Visit(ILE->getInit(i));
       Elts.push_back(C);
     }
 
+    for (; i < NumElements; ++i)
+      Elts.push_back(llvm::Constant::getNullValue(ElemTy));
+
     return llvm::ConstantVector::get(VType, Elts);    
   }
                                           

Modified: cfe/trunk/test/CodeGen/vector.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/vector.c?rev=51769&r1=51768&r2=51769&view=diff

==============================================================================
--- cfe/trunk/test/CodeGen/vector.c (original)
+++ cfe/trunk/test/CodeGen/vector.c Fri May 30 07:02:14 2008
@@ -5,3 +5,7 @@
 {
     __v4hi A = (__v4hi)0LL;
 }
+
+__v4hi x = {1,2,3};
+__v4hi y = {1,2,3,4};
+__v4hi z = {1,2,3,4,5};





More information about the cfe-commits mailing list