/// isValidReturnType - Return true if the specified type is valid as a return
/// type.
bool FunctionType::isValidReturnType(const Type *RetTy) {
- if (const PointerType *PTy = dyn_cast<PointerType>(RetTy))
- return PTy->getElementType()->getTypeID() != MetadataTyID;
-
return RetTy->getTypeID() != LabelTyID &&
RetTy->getTypeID() != MetadataTyID;
}
/// isValidArgumentType - Return true if the specified type is valid as an
/// argument type.
bool FunctionType::isValidArgumentType(const Type *ArgTy) {
- if ((!ArgTy->isFirstClassType() && !isa<OpaqueType>(ArgTy)) ||
- (isa<PointerType>(ArgTy) &&
- cast<PointerType>(ArgTy)->getElementType()->getTypeID() == MetadataTyID))
- return false;
-
- return true;
+ return ArgTy->isFirstClassType() || isa<OpaqueType>(ArgTy);
}
FunctionType::FunctionType(const Type *Result,
}
bool ArrayType::isValidElementType(const Type *ElemTy) {
- 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()->getTypeID() == MetadataTyID)
- return false;
-
- return true;
+ return ElemTy->getTypeID() != VoidTyID && ElemTy->getTypeID() != LabelTyID &&
+ ElemTy->getTypeID() != MetadataTyID && !isa<FunctionType>(ElemTy);
}
VectorType *VectorType::get(const Type *ElementType, unsigned NumElements) {
}
bool VectorType::isValidElementType(const Type *ElemTy) {
- if (ElemTy->isInteger() || ElemTy->isFloatingPoint() ||
- isa<OpaqueType>(ElemTy))
- return true;
-
- return false;
+ return ElemTy->isInteger() || ElemTy->isFloatingPoint() ||
+ isa<OpaqueType>(ElemTy);
}
//===----------------------------------------------------------------------===//
}
bool StructType::isValidElementType(const Type *ElemTy) {
- 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()->getTypeID() == MetadataTyID)
- return false;
-
- return true;
+ return ElemTy->getTypeID() != VoidTyID && ElemTy->getTypeID() != LabelTyID &&
+ ElemTy->getTypeID() != MetadataTyID && !isa<FunctionType>(ElemTy);
}
}
bool PointerType::isValidElementType(const Type *ElemTy) {
- if (ElemTy->getTypeID() == VoidTyID ||
- ElemTy->getTypeID() == LabelTyID)
- return false;
-
- if (const PointerType *PTy = dyn_cast<PointerType>(ElemTy))
- if (PTy->getElementType()->getTypeID() == MetadataTyID)
- return false;
-
- return true;
+ return ElemTy->getTypeID() != VoidTyID &&
+ ElemTy->getTypeID() != LabelTyID &&
+ ElemTy->getTypeID() != MetadataTyID;
}
Assert1(!GV.isConstant(), "'common' global may not be marked constant!",
&GV);
}
-
- // Verify that any metadata used in a global initializer points only to
- // other globals.
- if (MDNode *FirstNode = dyn_cast<MDNode>(GV.getInitializer())) {
- SmallVector<const MDNode *, 4> NodesToAnalyze;
- NodesToAnalyze.push_back(FirstNode);
- while (!NodesToAnalyze.empty()) {
- const MDNode *N = NodesToAnalyze.back();
- NodesToAnalyze.pop_back();
-
- for (MDNode::const_elem_iterator I = N->elem_begin(),
- E = N->elem_end(); I != E; ++I)
- if (const Value *V = *I) {
- if (const MDNode *Next = dyn_cast<MDNode>(V))
- NodesToAnalyze.push_back(Next);
- else
- Assert3(isa<Constant>(V),
- "reference to instruction from global metadata node",
- &GV, N, V);
- }
- }
- }
} else {
Assert1(GV.hasExternalLinkage() || GV.hasDLLImportLinkage() ||
GV.hasExternalWeakLinkage(),
"# formal arguments must match # of arguments for function type!",
&F, FT);
Assert1(F.getReturnType()->isFirstClassType() ||
- F.getReturnType() == Type::getVoidTy(F.getContext()) ||
+ F.getReturnType()->getTypeID() == Type::VoidTyID ||
isa<StructType>(F.getReturnType()),
"Functions cannot return aggregate values!", &F);
Assert1(!F.hasStructRetAttr() ||
- F.getReturnType() == Type::getVoidTy(F.getContext()),
+ F.getReturnType()->getTypeID() == Type::VoidTyID,
"Invalid struct return type!", &F);
const AttrListPtr &Attrs = F.getAttributes();
bool isLLVMdotName = F.getName().size() >= 5 &&
F.getName().substr(0, 5) == "llvm.";
- if (!isLLVMdotName)
- Assert1(F.getReturnType() != Type::getMetadataTy(F.getContext()),
- "Function may not return metadata unless it's an intrinsic", &F);
// Check that the argument values match the function type for this function...
unsigned i = 0;
void Verifier::visitReturnInst(ReturnInst &RI) {
Function *F = RI.getParent()->getParent();
unsigned N = RI.getNumOperands();
- if (F->getReturnType() == Type::getVoidTy(RI.getContext()))
+ if (F->getReturnType()->getTypeID() == Type::VoidTyID)
Assert2(N == 0,
"Found return instr that returns non-void in Function of void "
"return type!", &RI, F->getReturnType());
// Verify that there's no metadata unless it's a direct call to an intrinsic.
if (!CS.getCalledFunction() || CS.getCalledFunction()->getName().size() < 5 ||
CS.getCalledFunction()->getName().substr(0, 5) != "llvm.") {
- Assert1(FTy->getReturnType() != Type::getMetadataTy(I->getContext()),
- "Only intrinsics may return metadata", I);
for (FunctionType::param_iterator PI = FTy->param_begin(),
PE = FTy->param_end(); PI != PE; ++PI)
Assert1(PI->get() != Type::getMetadataTy(I->getContext()),
const Type *ElTy = PTy->getElementType();
Assert2(ElTy == LI.getType(),
"Load result type does not match pointer operand type!", &LI, ElTy);
- Assert1(ElTy != Type::getMetadataTy(LI.getContext()),
- "Can't load metadata!", &LI);
visitInstruction(LI);
}
Assert2(ElTy == SI.getOperand(0)->getType(),
"Stored value type does not match pointer operand type!",
&SI, ElTy);
- Assert1(ElTy != Type::getMetadataTy(SI.getContext()),
- "Can't store metadata!", &SI);
visitInstruction(SI);
}
// Check that the return value of the instruction is either void or a legal
// value type.
- Assert1(I.getType() == Type::getVoidTy(I.getContext()) ||
- I.getType()->isFirstClassType()
- || ((isa<CallInst>(I) || isa<InvokeInst>(I))
- && isa<StructType>(I.getType())),
+ Assert1(I.getType()->getTypeID() == Type::VoidTyID ||
+ I.getType()->isFirstClassType(),
"Instruction returns a non-scalar type!", &I);
- // Check that the instruction doesn't produce metadata or metadata*. Calls
- // all already checked against the callee type.
- Assert1(I.getType() != Type::getMetadataTy(I.getContext()) ||
+ // Check that the instruction doesn't produce metadata. Calls are already
+ // checked against the callee type.
+ Assert1(I.getType()->getTypeID() != Type::MetadataTyID ||
isa<CallInst>(I) || isa<InvokeInst>(I),
"Invalid use of metadata!", &I);
- if (const PointerType *PTy = dyn_cast<PointerType>(I.getType()))
- Assert1(PTy->getElementType() != Type::getMetadataTy(I.getContext()),
- "Instructions may not produce pointer to metadata.", &I);
-
// Check that all uses of the instruction, if they are instructions
// themselves, actually have parent basic blocks. If the use is not an
// instruction, it is an error!
Assert1(0, "Instruction operands must be first-class values!", &I);
}
- if (const PointerType *PTy =
- dyn_cast<PointerType>(I.getOperand(i)->getType()))
- Assert1(PTy->getElementType() != Type::getMetadataTy(I.getContext()),
- "Invalid use of metadata pointer.", &I);
-
if (Function *F = dyn_cast<Function>(I.getOperand(i))) {
// Check to make sure that the "address of" an intrinsic function is never
// taken.