From d67a1666ec70001ee9ce4c80ea5b0ab8e4f7a77b Mon Sep 17 00:00:00 2001 From: Nick Lewycky Date: Mon, 25 May 2009 21:28:11 +0000 Subject: [PATCH] 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. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@72402 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/VMCore/Type.cpp | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/lib/VMCore/Type.cpp b/lib/VMCore/Type.cpp index 5dd91b3d070..1cab6ba9e2c 100644 --- a/lib/VMCore/Type.cpp +++ b/lib/VMCore/Type.cpp @@ -322,15 +322,15 @@ FunctionType::FunctionType(const Type *Result, ContainedTys = reinterpret_cast(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(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 @@ StructType::StructType(const std::vector &Types, bool isPacked) 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] && " 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 @@ static ManagedStatic > ArrayTypes; 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 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 @@ static ManagedStatic > VectorTypes; VectorType *VectorType::get(const Type *ElementType, unsigned NumElements) { - assert(ElementType && "Can't get vector of null types!"); + assert(ElementType && "Can't get vector of types!"); VectorValType PVT(ElementType, NumElements); VectorType *PT = VectorTypes->get(PVT); -- 2.34.1