mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2024-12-13 20:32:21 +00:00
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:
parent
dd4238e04d
commit
1fbb13e4fa
@ -364,11 +364,10 @@ const IntegerType *Type::getInt64Ty(LLVMContext &C) {
|
|||||||
bool FunctionType::isValidReturnType(const Type *RetTy) {
|
bool FunctionType::isValidReturnType(const Type *RetTy) {
|
||||||
if (RetTy->isFirstClassType()) {
|
if (RetTy->isFirstClassType()) {
|
||||||
if (const PointerType *PTy = dyn_cast<PointerType>(RetTy))
|
if (const PointerType *PTy = dyn_cast<PointerType>(RetTy))
|
||||||
return PTy->getElementType() != Type::getMetadataTy(RetTy->getContext());
|
return PTy->getElementType()->getTypeID() != MetadataTyID;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (RetTy == Type::getVoidTy(RetTy->getContext()) ||
|
if (RetTy->getTypeID() == VoidTyID || RetTy->getTypeID() == MetadataTyID ||
|
||||||
RetTy == Type::getMetadataTy(RetTy->getContext()) ||
|
|
||||||
isa<OpaqueType>(RetTy))
|
isa<OpaqueType>(RetTy))
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
@ -389,8 +388,7 @@ bool FunctionType::isValidReturnType(const Type *RetTy) {
|
|||||||
bool FunctionType::isValidArgumentType(const Type *ArgTy) {
|
bool FunctionType::isValidArgumentType(const Type *ArgTy) {
|
||||||
if ((!ArgTy->isFirstClassType() && !isa<OpaqueType>(ArgTy)) ||
|
if ((!ArgTy->isFirstClassType() && !isa<OpaqueType>(ArgTy)) ||
|
||||||
(isa<PointerType>(ArgTy) &&
|
(isa<PointerType>(ArgTy) &&
|
||||||
cast<PointerType>(ArgTy)->getElementType() ==
|
cast<PointerType>(ArgTy)->getElementType()->getTypeID() == MetadataTyID))
|
||||||
Type::getMetadataTy(ArgTy->getContext())))
|
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
@ -829,13 +827,12 @@ ArrayType *ArrayType::get(const Type *ElementType, uint64_t NumElements) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool ArrayType::isValidElementType(const Type *ElemTy) {
|
bool ArrayType::isValidElementType(const Type *ElemTy) {
|
||||||
if (ElemTy == Type::getVoidTy(ElemTy->getContext()) ||
|
if (ElemTy->getTypeID() == VoidTyID || ElemTy->getTypeID() == LabelTyID ||
|
||||||
ElemTy == Type::getLabelTy(ElemTy->getContext()) ||
|
ElemTy->getTypeID() == MetadataTyID || isa<FunctionType>(ElemTy))
|
||||||
ElemTy == Type::getMetadataTy(ElemTy->getContext()))
|
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (const PointerType *PTy = dyn_cast<PointerType>(ElemTy))
|
if (const PointerType *PTy = dyn_cast<PointerType>(ElemTy))
|
||||||
if (PTy->getElementType() == Type::getMetadataTy(ElemTy->getContext()))
|
if (PTy->getElementType()->getTypeID() == MetadataTyID)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
@ -909,13 +906,12 @@ StructType *StructType::get(LLVMContext &Context, const Type *type, ...) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool StructType::isValidElementType(const Type *ElemTy) {
|
bool StructType::isValidElementType(const Type *ElemTy) {
|
||||||
if (ElemTy == Type::getVoidTy(ElemTy->getContext()) ||
|
if (ElemTy->getTypeID() == VoidTyID || ElemTy->getTypeID() == LabelTyID ||
|
||||||
ElemTy == Type::getLabelTy(ElemTy->getContext()) ||
|
ElemTy->getTypeID() == MetadataTyID || isa<FunctionType>(ElemTy))
|
||||||
ElemTy == Type::getMetadataTy(ElemTy->getContext()))
|
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (const PointerType *PTy = dyn_cast<PointerType>(ElemTy))
|
if (const PointerType *PTy = dyn_cast<PointerType>(ElemTy))
|
||||||
if (PTy->getElementType() == Type::getMetadataTy(ElemTy->getContext()))
|
if (PTy->getElementType()->getTypeID() == MetadataTyID)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
@ -928,7 +924,7 @@ bool StructType::isValidElementType(const Type *ElemTy) {
|
|||||||
|
|
||||||
PointerType *PointerType::get(const Type *ValueType, unsigned AddressSpace) {
|
PointerType *PointerType::get(const Type *ValueType, unsigned AddressSpace) {
|
||||||
assert(ValueType && "Can't get a pointer to <null> type!");
|
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!");
|
"Pointer to void is not valid, use i8* instead!");
|
||||||
assert(isValidElementType(ValueType) && "Invalid type for pointer element!");
|
assert(isValidElementType(ValueType) && "Invalid type for pointer element!");
|
||||||
PointerValType PVT(ValueType, AddressSpace);
|
PointerValType PVT(ValueType, AddressSpace);
|
||||||
@ -955,12 +951,12 @@ PointerType *Type::getPointerTo(unsigned addrs) const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool PointerType::isValidElementType(const Type *ElemTy) {
|
bool PointerType::isValidElementType(const Type *ElemTy) {
|
||||||
if (ElemTy == Type::getVoidTy(ElemTy->getContext()) ||
|
if (ElemTy->getTypeID() == VoidTyID ||
|
||||||
ElemTy == Type::getLabelTy(ElemTy->getContext()))
|
ElemTy->getTypeID() == LabelTyID)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (const PointerType *PTy = dyn_cast<PointerType>(ElemTy))
|
if (const PointerType *PTy = dyn_cast<PointerType>(ElemTy))
|
||||||
if (PTy->getElementType() == Type::getMetadataTy(ElemTy->getContext()))
|
if (PTy->getElementType()->getTypeID() == MetadataTyID)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
6
test/Other/2009-09-14-function-elements.ll
Normal file
6
test/Other/2009-09-14-function-elements.ll
Normal 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) }
|
Loading…
Reference in New Issue
Block a user