[llvm-branch-commits] [llvm-branch] r134487 - /llvm/branches/type-system-rewrite/lib/VMCore/Constants.cpp

Chris Lattner sabre at nondot.org
Wed Jul 6 00:44:03 PDT 2011


Author: lattner
Date: Wed Jul  6 02:44:03 2011
New Revision: 134487

URL: http://llvm.org/viewvc/llvm-project?rev=134487&view=rev
Log:
allow instantiating a constantstruct with an opaque struct type.

Modified:
    llvm/branches/type-system-rewrite/lib/VMCore/Constants.cpp

Modified: llvm/branches/type-system-rewrite/lib/VMCore/Constants.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/type-system-rewrite/lib/VMCore/Constants.cpp?rev=134487&r1=134486&r2=134487&view=diff
==============================================================================
--- llvm/branches/type-system-rewrite/lib/VMCore/Constants.cpp (original)
+++ llvm/branches/type-system-rewrite/lib/VMCore/Constants.cpp Wed Jul  6 02:44:03 2011
@@ -640,13 +640,13 @@
   : Constant(T, ConstantStructVal,
              OperandTraits<ConstantStruct>::op_end(this) - V.size(),
              V.size()) {
-  assert(V.size() == T->getNumElements() &&
+  assert((T->isOpaque() || V.size() == T->getNumElements()) &&
          "Invalid initializer vector for constant structure");
   Use *OL = OperandList;
   for (std::vector<Constant*>::const_iterator I = V.begin(), E = V.end();
        I != E; ++I, ++OL) {
     Constant *C = *I;
-    assert(C->getType() == T->getElementType(I-V.begin()) &&
+    assert((T->isOpaque() || C->getType() == T->getElementType(I-V.begin())) &&
            "Initializer for struct element doesn't match struct element type!");
     *OL = C;
   }
@@ -654,14 +654,13 @@
 
 // ConstantStruct accessors.
 Constant *ConstantStruct::get(const StructType *ST, ArrayRef<Constant*> V) {
-  assert(ST->getNumElements() == V.size() &&
-         "Incorrect # elements specified to ConstantStruct::get");
-  
   // Create a ConstantAggregateZero value if all elements are zeros.
   for (unsigned i = 0, e = V.size(); i != e; ++i)
     if (!V[i]->isNullValue())
       return ST->getContext().pImpl->StructConstants.getOrCreate(ST, V);
 
+  assert((ST->isOpaque() || ST->getNumElements() == V.size()) &&
+         "Incorrect # elements specified to ConstantStruct::get");
   return ConstantAggregateZero::get(ST);
 }
 





More information about the llvm-branch-commits mailing list