[llvm-commits] [llvm] r72402 - /llvm/trunk/lib/VMCore/Type.cpp

Nick Lewycky nicholas at mxc.ca
Mon May 25 14:28:11 PDT 2009


Author: nicholas
Date: Mon May 25 16:28:11 2009
New Revision: 72402

URL: http://llvm.org/viewvc/llvm-project?rev=72402&view=rev
Log:
Audit the type constructors. Previously it was possible to create [0 x void]
or use labels as members of structures for example. Also included a couple of
whitespace fixes.

Modified:
    llvm/trunk/lib/VMCore/Type.cpp

Modified: llvm/trunk/lib/VMCore/Type.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/VMCore/Type.cpp?rev=72402&r1=72401&r2=72402&view=diff

==============================================================================
--- llvm/trunk/lib/VMCore/Type.cpp (original)
+++ llvm/trunk/lib/VMCore/Type.cpp Mon May 25 16:28:11 2009
@@ -322,15 +322,15 @@
   ContainedTys = reinterpret_cast<PATypeHandle*>(this+1);
   NumContainedTys = Params.size() + 1; // + 1 for result type
   assert(isValidReturnType(Result) && "invalid return type for function");
-    
-    
+
+
   bool isAbstract = Result->isAbstract();
   new (&ContainedTys[0]) PATypeHandle(Result, this);
 
   for (unsigned i = 0; i != Params.size(); ++i) {
     assert((Params[i]->isFirstClassType() || isa<OpaqueType>(Params[i])) &&
            "Function arguments must be value types!");
-    new (&ContainedTys[i+1]) PATypeHandle(Params[i],this);
+    new (&ContainedTys[i+1]) PATypeHandle(Params[i], this);
     isAbstract |= Params[i]->isAbstract();
   }
 
@@ -345,8 +345,10 @@
   setSubclassData(isPacked);
   bool isAbstract = false;
   for (unsigned i = 0; i < Types.size(); ++i) {
-    assert(Types[i] != Type::VoidTy && "Void type for structure field!!");
-     new (&ContainedTys[i]) PATypeHandle(Types[i], this);
+    assert(Types[i] && "<null> type for structure field!");
+    assert(Types[i] != Type::VoidTy && "Void type for structure field!");
+    assert(Types[i] != Type::LabelTy && "Label type for structure field!");
+    new (&ContainedTys[i]) PATypeHandle(Types[i], this);
     isAbstract |= Types[i]->isAbstract();
   }
 
@@ -1038,7 +1040,9 @@
 
 
 ArrayType *ArrayType::get(const Type *ElementType, uint64_t NumElements) {
-  assert(ElementType && "Can't get array of null types!");
+  assert(ElementType && "Can't get array of <null> types!");
+  assert(ElementType != Type::VoidTy && "Array of void is not valid!");
+  assert(ElementType != Type::LabelTy && "Array of labels is not valid!");
 
   ArrayValType AVT(ElementType, NumElements);
   ArrayType *AT = ArrayTypes->get(AVT);
@@ -1082,7 +1086,7 @@
 
 
 VectorType *VectorType::get(const Type *ElementType, unsigned NumElements) {
-  assert(ElementType && "Can't get vector of null types!");
+  assert(ElementType && "Can't get vector of <null> types!");
 
   VectorValType PVT(ElementType, NumElements);
   VectorType *PT = VectorTypes->get(PVT);





More information about the llvm-commits mailing list