X-Git-Url: http://demsky.eecs.uci.edu/git/?a=blobdiff_plain;f=lib%2FVMCore%2FVerifier.cpp;h=139e035230191c3fc91da21f2d1ad8d53c774cb1;hb=9a767330f555f21d6ef311d3a348d3a44f306d35;hp=4de1282caf9b3edd80f9ef429141b0331107abd5;hpb=dacfc5d37f649fb15aaa339eaf1b010c4f44c803;p=oota-llvm.git diff --git a/lib/VMCore/Verifier.cpp b/lib/VMCore/Verifier.cpp index 4de1282caf9..139e0352301 100644 --- a/lib/VMCore/Verifier.cpp +++ b/lib/VMCore/Verifier.cpp @@ -72,7 +72,9 @@ namespace { // Anonymous namespace for class struct PreVerifier : public FunctionPass { static char ID; // Pass ID, replacement for typeid - PreVerifier() : FunctionPass(&ID) { } + PreVerifier() : FunctionPass(ID) { + initializePreVerifierPass(*PassRegistry::getPassRegistry()); + } virtual void getAnalysisUsage(AnalysisUsage &AU) const { AU.setPreservesAll(); @@ -102,9 +104,9 @@ namespace { // Anonymous namespace for class } char PreVerifier::ID = 0; -static RegisterPass -PreVer("preverify", "Preliminary module verification"); -static const PassInfo *const PreVerifyID = &PreVer; +INITIALIZE_PASS(PreVerifier, "preverify", "Preliminary module verification", + false, false) +static char &PreVerifyID = PreVerifier::ID; namespace { class TypeSet : public AbstractTypeUser { @@ -182,23 +184,17 @@ namespace { SmallPtrSet MDNodes; Verifier() - : FunctionPass(&ID), + : FunctionPass(ID), Broken(false), RealPass(true), action(AbortProcessAction), - Mod(0), Context(0), DT(0), MessagesStr(Messages) {} + Mod(0), Context(0), DT(0), MessagesStr(Messages) { + initializeVerifierPass(*PassRegistry::getPassRegistry()); + } explicit Verifier(VerifierFailureAction ctn) - : FunctionPass(&ID), + : FunctionPass(ID), Broken(false), RealPass(true), action(ctn), Mod(0), Context(0), DT(0), - MessagesStr(Messages) {} - explicit Verifier(bool AB) - : FunctionPass(&ID), - Broken(false), RealPass(true), - action( AB ? AbortProcessAction : PrintMessageAction), Mod(0), - Context(0), DT(0), MessagesStr(Messages) {} - explicit Verifier(DominatorTree &dt) - : FunctionPass(&ID), - Broken(false), RealPass(false), action(PrintMessageAction), Mod(0), - Context(0), DT(&dt), MessagesStr(Messages) {} - + MessagesStr(Messages) { + initializeVerifierPass(*PassRegistry::getPassRegistry()); + } bool doInitialization(Module &M) { Mod = &M; @@ -403,7 +399,10 @@ namespace { } // End anonymous namespace char Verifier::ID = 0; -static RegisterPass X("verify", "Module Verifier"); +INITIALIZE_PASS_BEGIN(Verifier, "verify", "Module Verifier", false, false) +INITIALIZE_PASS_DEPENDENCY(PreVerifier) +INITIALIZE_PASS_DEPENDENCY(DominatorTree) +INITIALIZE_PASS_END(Verifier, "verify", "Module Verifier", false, false) // Assert - We know that cond should be true, if not print an error message. #define Assert(C, M) \ @@ -446,6 +445,10 @@ void Verifier::visitGlobalValue(GlobalValue &GV) { Assert1(GVar && GVar->getType()->getElementType()->isArrayTy(), "Only global arrays can have appending linkage!", GVar); } + + Assert1(!GV.hasLinkerPrivateWeakDefAutoLinkage() || GV.hasDefaultVisibility(), + "linker_private_weak_def_auto can only have default visibility!", + &GV); } void Verifier::visitGlobalVariable(GlobalVariable &GV) { @@ -468,6 +471,23 @@ void Verifier::visitGlobalVariable(GlobalVariable &GV) { "invalid linkage type for global declaration", &GV); } + if (GV.hasName() && (GV.getName() == "llvm.global_ctors" || + GV.getName() == "llvm.global_dtors")) { + Assert1(!GV.hasInitializer() || GV.hasAppendingLinkage(), + "invalid linkage for intrinsic global variable", &GV); + // Don't worry about emitting an error for it not being an array, + // visitGlobalValue will complain on appending non-array. + if (const ArrayType *ATy = dyn_cast(GV.getType())) { + const StructType *STy = dyn_cast(ATy->getElementType()); + const PointerType *FuncPtrTy = + FunctionType::get(Type::getVoidTy(*Context), false)->getPointerTo(); + Assert1(STy && STy->getNumElements() == 2 && + STy->getTypeAtIndex(0u)->isIntegerTy(32) && + STy->getTypeAtIndex(1) == FuncPtrTy, + "wrong type for intrinsic global variable", &GV); + } + } + visitGlobalValue(GV); } @@ -481,6 +501,7 @@ void Verifier::visitGlobalAlias(GlobalAlias &GA) { "Aliasee cannot be NULL!", &GA); Assert1(GA.getType() == GA.getAliasee()->getType(), "Alias and aliasee types should match!", &GA); + Assert1(!GA.hasUnnamedAddr(), "Alias cannot have unnamed_addr!", &GA); if (!isa(GA.getAliasee())) { const ConstantExpr *CE = dyn_cast(GA.getAliasee()); @@ -691,6 +712,8 @@ void Verifier::visitFunction(Function &F) { case CallingConv::Cold: case CallingConv::X86_FastCall: case CallingConv::X86_ThisCall: + case CallingConv::PTX_Kernel: + case CallingConv::PTX_Device: Assert1(!F.isVarArg(), "Varargs functions must have C calling conventions!", &F); break; @@ -820,30 +843,10 @@ void Verifier::visitReturnInst(ReturnInst &RI) { Assert2(N == 0, "Found return instr that returns non-void in Function of void " "return type!", &RI, F->getReturnType()); - else if (N == 1 && F->getReturnType() == RI.getOperand(0)->getType()) { - // Exactly one return value and it matches the return type. Good. - } else if (const StructType *STy = dyn_cast(F->getReturnType())) { - // The return type is a struct; check for multiple return values. - Assert2(STy->getNumElements() == N, - "Incorrect number of return values in ret instruction!", - &RI, 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 if (const ArrayType *ATy = dyn_cast(F->getReturnType())) { - // The return type is an array; check for multiple return values. - Assert2(ATy->getNumElements() == N, - "Incorrect number of return values in ret instruction!", - &RI, F->getReturnType()); - for (unsigned i = 0; i != N; ++i) - Assert2(ATy->getElementType() == RI.getOperand(i)->getType(), - "Function return type does not match operand " - "type of return inst!", &RI, F->getReturnType()); - } else { - CheckFailed("Function return type does not match operand " - "type of return inst!", &RI, F->getReturnType()); - } + else + Assert2(N == 1 && F->getReturnType() == RI.getOperand(0)->getType(), + "Function return type does not match operand " + "type of return inst!", &RI, F->getReturnType()); // Check to make sure that the return value has necessary properties for // terminators... @@ -1278,28 +1281,37 @@ void Verifier::visitBinaryOperator(BinaryOperator &B) { visitInstruction(B); } -void Verifier::visitICmpInst(ICmpInst& IC) { +void Verifier::visitICmpInst(ICmpInst &IC) { // Check that the operands are the same type - const Type* Op0Ty = IC.getOperand(0)->getType(); - const Type* Op1Ty = IC.getOperand(1)->getType(); + const Type *Op0Ty = IC.getOperand(0)->getType(); + const Type *Op1Ty = IC.getOperand(1)->getType(); Assert1(Op0Ty == Op1Ty, "Both operands to ICmp instruction are not of the same type!", &IC); // Check that the operands are the right type Assert1(Op0Ty->isIntOrIntVectorTy() || Op0Ty->isPointerTy(), "Invalid operand types for ICmp instruction", &IC); + // Check that the predicate is valid. + Assert1(IC.getPredicate() >= CmpInst::FIRST_ICMP_PREDICATE && + IC.getPredicate() <= CmpInst::LAST_ICMP_PREDICATE, + "Invalid predicate in ICmp instruction!", &IC); visitInstruction(IC); } -void Verifier::visitFCmpInst(FCmpInst& FC) { +void Verifier::visitFCmpInst(FCmpInst &FC) { // Check that the operands are the same type - const Type* Op0Ty = FC.getOperand(0)->getType(); - const Type* Op1Ty = FC.getOperand(1)->getType(); + const Type *Op0Ty = FC.getOperand(0)->getType(); + const Type *Op1Ty = FC.getOperand(1)->getType(); Assert1(Op0Ty == Op1Ty, "Both operands to FCmp instruction are not of the same type!", &FC); // Check that the operands are the right type Assert1(Op0Ty->isFPOrFPVectorTy(), "Invalid operand types for FCmp instruction", &FC); + // Check that the predicate is valid. + Assert1(FC.getPredicate() >= CmpInst::FIRST_FCMP_PREDICATE && + FC.getPredicate() <= CmpInst::LAST_FCMP_PREDICATE, + "Invalid predicate in FCmp instruction!", &FC); + visitInstruction(FC); } @@ -1322,27 +1334,6 @@ void Verifier::visitShuffleVectorInst(ShuffleVectorInst &SV) { Assert1(ShuffleVectorInst::isValidOperands(SV.getOperand(0), SV.getOperand(1), SV.getOperand(2)), "Invalid shufflevector operands!", &SV); - - const VectorType *VTy = dyn_cast(SV.getOperand(0)->getType()); - Assert1(VTy, "Operands are not a vector type", &SV); - - // Check to see if Mask is valid. - if (const ConstantVector *MV = dyn_cast(SV.getOperand(2))) { - for (unsigned i = 0, e = MV->getNumOperands(); i != e; ++i) { - if (ConstantInt* CI = dyn_cast(MV->getOperand(i))) { - Assert1(!CI->uge(VTy->getNumElements()*2), - "Invalid shufflevector shuffle mask!", &SV); - } else { - Assert1(isa(MV->getOperand(i)), - "Invalid shufflevector shuffle mask!", &SV); - } - } - } else { - Assert1(isa(SV.getOperand(2)) || - isa(SV.getOperand(2)), - "Invalid shufflevector shuffle mask!", &SV); - } - visitInstruction(SV); } @@ -1578,7 +1569,8 @@ void Verifier::VerifyType(const Type *Ty) { "Function type with invalid parameter type", ElTy, FTy); VerifyType(ElTy); } - } break; + break; + } case Type::StructTyID: { const StructType *STy = cast(Ty); for (unsigned i = 0, e = STy->getNumElements(); i != e; ++i) { @@ -1587,34 +1579,29 @@ void Verifier::VerifyType(const Type *Ty) { "Structure type with invalid element type", ElTy, STy); VerifyType(ElTy); } - } break; - case Type::UnionTyID: { - const UnionType *UTy = cast(Ty); - for (unsigned i = 0, e = UTy->getNumElements(); i != e; ++i) { - const Type *ElTy = UTy->getElementType(i); - Assert2(UnionType::isValidElementType(ElTy), - "Union type with invalid element type", ElTy, UTy); - VerifyType(ElTy); - } - } break; + break; + } case Type::ArrayTyID: { const ArrayType *ATy = cast(Ty); Assert1(ArrayType::isValidElementType(ATy->getElementType()), "Array type with invalid element type", ATy); VerifyType(ATy->getElementType()); - } break; + break; + } case Type::PointerTyID: { const PointerType *PTy = cast(Ty); Assert1(PointerType::isValidElementType(PTy->getElementType()), "Pointer type with invalid element type", PTy); VerifyType(PTy->getElementType()); - } break; + break; + } case Type::VectorTyID: { const VectorType *VTy = cast(Ty); Assert1(VectorType::isValidElementType(VTy->getElementType()), "Vector type with invalid element type", VTy); VerifyType(VTy->getElementType()); - } break; + break; + } default: break; } @@ -1658,6 +1645,9 @@ void Verifier::visitIntrinsicFunctionCall(Intrinsic::ID ID, CallInst &CI) { Assert1(isa(CI.getArgOperand(3)), "alignment argument of memory intrinsics must be a constant int", &CI); + Assert1(isa(CI.getArgOperand(4)), + "isvolatile argument of memory intrinsics must be a constant int", + &CI); break; case Intrinsic::gcroot: case Intrinsic::gcwrite: @@ -1665,10 +1655,14 @@ void Verifier::visitIntrinsicFunctionCall(Intrinsic::ID ID, CallInst &CI) { if (ID == Intrinsic::gcroot) { AllocaInst *AI = dyn_cast(CI.getArgOperand(0)->stripPointerCasts()); - Assert1(AI && AI->getType()->getElementType()->isPointerTy(), - "llvm.gcroot parameter #1 must be a pointer alloca.", &CI); + Assert1(AI, "llvm.gcroot parameter #1 must be an alloca.", &CI); Assert1(isa(CI.getArgOperand(1)), "llvm.gcroot parameter #2 must be a constant.", &CI); + if (!AI->getType()->getElementType()->isPointerTy()) { + Assert1(!isa(CI.getArgOperand(1)), + "llvm.gcroot parameter #1 must either be a pointer alloca, " + "or argument #2 must be a non-null constant.", &CI); + } } Assert1(CI.getParent()->getParent()->hasGC(), @@ -1840,8 +1834,13 @@ bool Verifier::PerformTypeCheck(Intrinsic::ID ID, Function *F, const Type *Ty, // and iPTR. In the verifier, we can not distinguish which case we have so // allow either case to be legal. if (const PointerType* PTyp = dyn_cast(Ty)) { - Suffix += ".p" + utostr(PTyp->getAddressSpace()) + - EVT::getEVT(PTyp->getElementType()).getEVTString(); + EVT PointeeVT = EVT::getEVT(PTyp->getElementType(), true); + if (PointeeVT == MVT::Other) { + CheckFailed("Intrinsic has pointer to complex type."); + return false; + } + Suffix += ".p" + utostr(PTyp->getAddressSpace()) + + PointeeVT.getEVTString(); } else { CheckFailed(IntrinsicParam(ArgNo, NumRetVals) + " is not a " "pointer and a pointer is required.", F);