diff options
author | Philip Reames <listmail@philipreames.com> | 2019-07-09 19:26:12 +0000 |
---|---|---|
committer | Philip Reames <listmail@philipreames.com> | 2019-07-09 19:26:12 +0000 |
commit | 3dbd7e98d86a306f7ba125d042846099a56b6ee9 (patch) | |
tree | 26f741b4f2bb11403ca61c8fa9edfa88fd2102ac /llvm/lib/Transforms/Instrumentation/PoisonChecking.cpp | |
parent | f09d54ed2a75b62960b35258136435d7c8d418e1 (diff) | |
download | bcm5719-llvm-3dbd7e98d86a306f7ba125d042846099a56b6ee9.tar.gz bcm5719-llvm-3dbd7e98d86a306f7ba125d042846099a56b6ee9.zip |
[PoisonCheker] Support for out of bounds operands on shifts + insert/extractelement
These are sources of poison which don't come from flags, but are clearly documented in the LangRef. Left off support for scalable vectors for the moment, but should be easy to add if anyone is interested.
llvm-svn: 365543
Diffstat (limited to 'llvm/lib/Transforms/Instrumentation/PoisonChecking.cpp')
-rw-r--r-- | llvm/lib/Transforms/Instrumentation/PoisonChecking.cpp | 42 |
1 files changed, 41 insertions, 1 deletions
diff --git a/llvm/lib/Transforms/Instrumentation/PoisonChecking.cpp b/llvm/lib/Transforms/Instrumentation/PoisonChecking.cpp index 8e4c046c9f8..0c4e64bbc54 100644 --- a/llvm/lib/Transforms/Instrumentation/PoisonChecking.cpp +++ b/llvm/lib/Transforms/Instrumentation/PoisonChecking.cpp @@ -169,14 +169,54 @@ static void generatePoisonChecksForBinOp(Instruction &I, } break; } + case Instruction::AShr: + case Instruction::LShr: + case Instruction::Shl: { + Value *ShiftCheck = + B.CreateICmp(ICmpInst::ICMP_UGE, RHS, + ConstantInt::get(RHS->getType(), + LHS->getType()->getScalarSizeInBits())); + Checks.push_back(ShiftCheck); + break; + } }; } static Value* generatePoisonChecks(Instruction &I) { IRBuilder<> B(&I); SmallVector<Value*, 2> Checks; - if (isa<BinaryOperator>(I)) + if (isa<BinaryOperator>(I) && !I.getType()->isVectorTy()) generatePoisonChecksForBinOp(I, Checks); + + // Handle non-binops seperately + switch (I.getOpcode()) { + default: + break; + case Instruction::ExtractElement: { + Value *Vec = I.getOperand(0); + if (Vec->getType()->getVectorIsScalable()) + break; + Value *Idx = I.getOperand(1); + unsigned NumElts = Vec->getType()->getVectorNumElements(); + Value *Check = + B.CreateICmp(ICmpInst::ICMP_UGE, Idx, + ConstantInt::get(Idx->getType(), NumElts)); + Checks.push_back(Check); + break; + } + case Instruction::InsertElement: { + Value *Vec = I.getOperand(0); + if (Vec->getType()->getVectorIsScalable()) + break; + Value *Idx = I.getOperand(2); + unsigned NumElts = Vec->getType()->getVectorNumElements(); + Value *Check = + B.CreateICmp(ICmpInst::ICMP_UGE, Idx, + ConstantInt::get(Idx->getType(), NumElts)); + Checks.push_back(Check); + break; + } + }; return buildOrChain(B, Checks); } |