diff options
author | Nuno Lopes <nunoplopes@sapo.pt> | 2012-06-18 16:04:04 +0000 |
---|---|---|
committer | Nuno Lopes <nunoplopes@sapo.pt> | 2012-06-18 16:04:04 +0000 |
commit | b7c941bad9b77d1456c2f5d01fca58dd641a5c01 (patch) | |
tree | 5c94edd63d37750ced3ed01623d52c1886d6e5be /llvm/lib/VMCore/Verifier.cpp | |
parent | 3237ce737e8100934ab9d80541de5a12683dec18 (diff) | |
download | bcm5719-llvm-b7c941bad9b77d1456c2f5d01fca58dd641a5c01.tar.gz bcm5719-llvm-b7c941bad9b77d1456c2f5d01fca58dd641a5c01.zip |
add the 'alloc' metadata node to represent the size of offset of buffers pointed to by pointers.
This metadata can be attached to any instruction returning a pointer
llvm-svn: 158660
Diffstat (limited to 'llvm/lib/VMCore/Verifier.cpp')
-rw-r--r-- | llvm/lib/VMCore/Verifier.cpp | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/llvm/lib/VMCore/Verifier.cpp b/llvm/lib/VMCore/Verifier.cpp index 477b81dc67f..2ca4854d9ac 100644 --- a/llvm/lib/VMCore/Verifier.cpp +++ b/llvm/lib/VMCore/Verifier.cpp @@ -1672,6 +1672,39 @@ void Verifier::visitInstruction(Instruction &I) { } } + if (MDNode *MD = I.getMetadata(LLVMContext::MD_alloc)) { + Assert1(I.getType()->isPointerTy(), "alloc requires a pointer result", &I); + Assert1(MD->getNumOperands() >= 1, "alloc takes at least one operand", &I); + Function *SizeFn = dyn_cast<Function>(MD->getOperand(0)); + Function *OffsetFn = MD->getNumOperands() >= 2 ? + dyn_cast_or_null<Function>(MD->getOperand(1)) : 0; + Assert1(SizeFn, "first parameter of alloc must be a function", &I); + Assert1(MD->getNumOperands() == 1 || !MD->getOperand(1) || OffsetFn, + "second parameter of alloc must be either a function or null", &I); + Assert1(SizeFn->onlyReadsMemory(), + "size function must be readonly/readnone", &I); + Assert1(!OffsetFn || OffsetFn->onlyReadsMemory(), + "offset function must be readonly/readnone", &I); + Assert1(SizeFn->getReturnType()->isIntegerTy(), + "size function must return an integer", &I); + Assert1(!OffsetFn || OffsetFn->getReturnType()->isIntegerTy(), + "offset function must return an integer", &I); + + FunctionType *SizeFnTy = SizeFn->getFunctionType(); + FunctionType *OffsetFnTy = OffsetFn ? OffsetFn->getFunctionType() : 0; + Assert1(SizeFnTy->getNumParams() == MD->getNumOperands()-2, + "size function number of parameters mismatch", &I); + Assert1(!OffsetFnTy || OffsetFnTy->getNumParams() == MD->getNumOperands()-2, + "offset function number of parameters mismatch", &I); + for (unsigned i = 0, e = SizeFnTy->getNumParams(); i != e; ++i) { + Assert1(SizeFnTy->getParamType(i) == MD->getOperand(i+2)->getType(), + "size function parameter type mismatch", &I); + if (OffsetFnTy) + Assert1(OffsetFnTy->getParamType(i) == MD->getOperand(i+2)->getType(), + "offset function parameter type mismatch", &I); + } + } + MDNode *MD = I.getMetadata(LLVMContext::MD_range); Assert1(!MD || isa<LoadInst>(I), "Ranges are only for loads!", &I); |