[llvm-commits] [llvm] r81846 - in /llvm/trunk: lib/VMCore/Type.cpp test/Other/2009-09-14-function-elements.ll
Nick Lewycky
nicholas at mxc.ca
Mon Sep 14 23:28:26 PDT 2009
Author: nicholas
Date: Tue Sep 15 01:28:26 2009
New Revision: 81846
URL: http://llvm.org/viewvc/llvm-project?rev=81846&view=rev
Log:
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.
Added:
llvm/trunk/test/Other/2009-09-14-function-elements.ll
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=81846&r1=81845&r2=81846&view=diff
==============================================================================
--- llvm/trunk/lib/VMCore/Type.cpp (original)
+++ llvm/trunk/lib/VMCore/Type.cpp Tue Sep 15 01:28:26 2009
@@ -364,11 +364,10 @@
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::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 @@
}
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 @@
}
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 @@
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 @@
}
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;
Added: llvm/trunk/test/Other/2009-09-14-function-elements.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Other/2009-09-14-function-elements.ll?rev=81846&view=auto
==============================================================================
--- llvm/trunk/test/Other/2009-09-14-function-elements.ll (added)
+++ llvm/trunk/test/Other/2009-09-14-function-elements.ll Tue Sep 15 01:28:26 2009
@@ -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.
+
+ at foo = external global [4 x i32 (i32)]
+ at bar = external global { i32 (i32) }
More information about the llvm-commits
mailing list