#include "llvm/Pass.h"
#include "llvm/Module.h"
#include "llvm/ModuleProvider.h"
-#include "llvm/ParameterAttributes.h"
+#include "llvm/ParamAttrsList.h"
#include "llvm/DerivedTypes.h"
#include "llvm/InlineAsm.h"
#include "llvm/IntrinsicInst.h"
&F, FT);
Assert1(F.getReturnType()->isFirstClassType() ||
F.getReturnType() == Type::VoidTy ||
- F.getReturnType()->getTypeID() == Type::StructTyID,
+ isa<StructType>(F.getReturnType()),
"Functions cannot return aggregate values!", &F);
- Assert1(!F.isStructReturn() || FT->getReturnType() == Type::VoidTy,
- "Invalid struct-return function!", &F);
+ Assert1(!F.hasStructRetAttr() || F.getReturnType() == Type::VoidTy,
+ "Invalid struct return type!", &F);
const ParamAttrsList *Attrs = F.getParamAttrs();
void Verifier::visitReturnInst(ReturnInst &RI) {
Function *F = RI.getParent()->getParent();
- if (RI.getNumOperands() == 0)
+ unsigned N = RI.getNumOperands();
+ if (N == 0)
Assert2(F->getReturnType() == Type::VoidTy,
"Found return instr that returns void in Function of non-void "
"return type!", &RI, F->getReturnType());
- else
+ else if (N == 1)
Assert2(F->getReturnType() == RI.getOperand(0)->getType(),
"Function return type does not match operand "
"type of return inst!", &RI, F->getReturnType());
+ else if (const StructType *STy = dyn_cast<StructType>(F->getReturnType())) {
+ for (unsigned i = 0; i < N; i++)
+ Assert2(STy->getElementType(i) == RI.getOperand(i)->getType(),
+ "Function return type does not match operand "
+ "type of return inst!", &RI, F->getReturnType());
+ } else
+ Assert1(0, "Invalid return type!", &RI);
// Check to make sure that the return value has necessary properties for
// terminators...
}
void Verifier::visitAllocationInst(AllocationInst &AI) {
- const PointerType *Ptr = AI.getType();
- Assert(Ptr->getAddressSpace() == 0,
- "Allocation instruction pointer not in the generic address space!");
+ const PointerType *PTy = AI.getType();
+ Assert1(PTy->getAddressSpace() == 0,
+ "Allocation instruction pointer not in the generic address space!",
+ &AI);
+ Assert1(PTy->getElementType()->isSized(), "Cannot allocate unsized type",
+ &AI);
visitInstruction(AI);
}
// Check that the return value of the instruction is either void or a legal
// value type.
- Assert1(I.getType() == Type::VoidTy || I.getType()->isFirstClassType(),
+ Assert1(I.getType() == Type::VoidTy || I.getType()->isFirstClassType()
+ || ((isa<CallInst>(I) || isa<InvokeInst>(I))
+ && isa<StructType>(I.getType())),
"Instruction returns a non-scalar type!", &I);
// Check that all uses of the instruction, if they are instructions
// Check to make sure that only first-class-values are operands to
// instructions.
- Assert1(I.getOperand(i)->getType()->isFirstClassType()
- || (isa<ReturnInst>(I)
- && I.getOperand(i)->getType()->getTypeID() == Type::StructTyID),
- "Instruction operands must be first-class values!", &I);
-
+ if (!I.getOperand(i)->getType()->isFirstClassType()) {
+ if (isa<ReturnInst>(I) || isa<GetResultInst>(I))
+ Assert1(isa<StructType>(I.getOperand(i)->getType()),
+ "Invalid ReturnInst operands!", &I);
+ else if (isa<CallInst>(I) || isa<InvokeInst>(I)) {
+ if (const PointerType *PT = dyn_cast<PointerType>
+ (I.getOperand(i)->getType())) {
+ const Type *ETy = PT->getElementType();
+ Assert1(isa<StructType>(ETy), "Invalid CallInst operands!", &I);
+ }
+ else
+ Assert1(0, "Invalid CallInst operands!", &I);
+ }
+ else
+ Assert1(0, "Instruction operands must be first-class values!", &I);
+ }
+
if (Function *F = dyn_cast<Function>(I.getOperand(i))) {
// Check to make sure that the "address of" an intrinsic function is never
// taken.