Forbid arrays of function-type and structures with function-typed fields.

While I'm there, change code that does:
  SomeTy == Type::getFooType(Context)
into:
  SomeTy->getTypeID() == FooTyID
to decrease the amount of useless type creation which may involve locking, etc.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@81846 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Nick Lewycky 2009-09-15 06:28:26 +00:00
parent dd4238e04d
commit 1fbb13e4fa
2 changed files with 19 additions and 17 deletions

View File

@ -364,11 +364,10 @@ const IntegerType *Type::getInt64Ty(LLVMContext &C) {
bool FunctionType::isValidReturnType(const Type *RetTy) {
if (RetTy->isFirstClassType()) {
if (const PointerType *PTy = dyn_cast<PointerType>(RetTy))
return PTy->getElementType() != Type::getMetadataTy(RetTy->getContext());
return PTy->getElementType()->getTypeID() != MetadataTyID;
return true;
}
if (RetTy == Type::getVoidTy(RetTy->getContext()) ||
RetTy == Type::getMetadataTy(RetTy->getContext()) ||
if (RetTy->getTypeID() == VoidTyID || RetTy->getTypeID() == MetadataTyID ||
isa<OpaqueType>(RetTy))
return true;
@ -389,8 +388,7 @@ bool FunctionType::isValidReturnType(const Type *RetTy) {
bool FunctionType::isValidArgumentType(const Type *ArgTy) {
if ((!ArgTy->isFirstClassType() && !isa<OpaqueType>(ArgTy)) ||
(isa<PointerType>(ArgTy) &&
cast<PointerType>(ArgTy)->getElementType() ==
Type::getMetadataTy(ArgTy->getContext())))
cast<PointerType>(ArgTy)->getElementType()->getTypeID() == MetadataTyID))
return false;
return true;
@ -829,13 +827,12 @@ ArrayType *ArrayType::get(const Type *ElementType, uint64_t NumElements) {
}
bool ArrayType::isValidElementType(const Type *ElemTy) {
if (ElemTy == Type::getVoidTy(ElemTy->getContext()) ||
ElemTy == Type::getLabelTy(ElemTy->getContext()) ||
ElemTy == Type::getMetadataTy(ElemTy->getContext()))
if (ElemTy->getTypeID() == VoidTyID || ElemTy->getTypeID() == LabelTyID ||
ElemTy->getTypeID() == MetadataTyID || isa<FunctionType>(ElemTy))
return false;
if (const PointerType *PTy = dyn_cast<PointerType>(ElemTy))
if (PTy->getElementType() == Type::getMetadataTy(ElemTy->getContext()))
if (PTy->getElementType()->getTypeID() == MetadataTyID)
return false;
return true;
@ -909,13 +906,12 @@ StructType *StructType::get(LLVMContext &Context, const Type *type, ...) {
}
bool StructType::isValidElementType(const Type *ElemTy) {
if (ElemTy == Type::getVoidTy(ElemTy->getContext()) ||
ElemTy == Type::getLabelTy(ElemTy->getContext()) ||
ElemTy == Type::getMetadataTy(ElemTy->getContext()))
if (ElemTy->getTypeID() == VoidTyID || ElemTy->getTypeID() == LabelTyID ||
ElemTy->getTypeID() == MetadataTyID || isa<FunctionType>(ElemTy))
return false;
if (const PointerType *PTy = dyn_cast<PointerType>(ElemTy))
if (PTy->getElementType() == Type::getMetadataTy(ElemTy->getContext()))
if (PTy->getElementType()->getTypeID() == MetadataTyID)
return false;
return true;
@ -928,7 +924,7 @@ bool StructType::isValidElementType(const Type *ElemTy) {
PointerType *PointerType::get(const Type *ValueType, unsigned AddressSpace) {
assert(ValueType && "Can't get a pointer to <null> type!");
assert(ValueType != Type::getVoidTy(ValueType->getContext()) &&
assert(ValueType->getTypeID() != VoidTyID &&
"Pointer to void is not valid, use i8* instead!");
assert(isValidElementType(ValueType) && "Invalid type for pointer element!");
PointerValType PVT(ValueType, AddressSpace);
@ -955,12 +951,12 @@ PointerType *Type::getPointerTo(unsigned addrs) const {
}
bool PointerType::isValidElementType(const Type *ElemTy) {
if (ElemTy == Type::getVoidTy(ElemTy->getContext()) ||
ElemTy == Type::getLabelTy(ElemTy->getContext()))
if (ElemTy->getTypeID() == VoidTyID ||
ElemTy->getTypeID() == LabelTyID)
return false;
if (const PointerType *PTy = dyn_cast<PointerType>(ElemTy))
if (PTy->getElementType() == Type::getMetadataTy(ElemTy->getContext()))
if (PTy->getElementType()->getTypeID() == MetadataTyID)
return false;
return true;

View File

@ -0,0 +1,6 @@
; RUN: not llvm-as %s -disable-output 2>/dev/null
; Arrays and structures with function types (not function pointers) are illegal.
@foo = external global [4 x i32 (i32)]
@bar = external global { i32 (i32) }