From: Evgeniy Stepanov Date: Wed, 5 Dec 2012 14:39:55 +0000 (+0000) Subject: [msan] Instrument bswap intrinsic. X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=8b51bab4958c0dddbfbbff92bc2ed0522dfec87b;p=platform%2Fupstream%2Fllvm.git [msan] Instrument bswap intrinsic. llvm-svn: 169383 --- diff --git a/llvm/lib/Transforms/Instrumentation/MemorySanitizer.cpp b/llvm/lib/Transforms/Instrumentation/MemorySanitizer.cpp index 183403d..3427512 100644 --- a/llvm/lib/Transforms/Instrumentation/MemorySanitizer.cpp +++ b/llvm/lib/Transforms/Instrumentation/MemorySanitizer.cpp @@ -1101,6 +1101,25 @@ struct MemorySanitizerVisitor : public InstVisitor { VAHelper->visitVACopyInst(I); } + void handleBswap(IntrinsicInst &I) { + IRBuilder<> IRB(&I); + Value *Op = I.getArgOperand(0); + Type *OpType = Op->getType(); + Function *BswapFunc = Intrinsic::getDeclaration( + F.getParent(), Intrinsic::bswap, ArrayRef(&OpType, 1)); + setShadow(&I, IRB.CreateCall(BswapFunc, getShadow(Op))); + setOrigin(&I, getOrigin(Op)); + } + + void visitIntrinsicInst(IntrinsicInst &I) { + switch (I.getIntrinsicID()) { + case llvm::Intrinsic::bswap: + handleBswap(I); break; + default: + visitInstruction(I); break; + } + } + void visitCallSite(CallSite CS) { Instruction &I = *CS.getInstruction(); assert((CS.isCall() || CS.isInvoke()) && "Unknown type of CallSite"); @@ -1120,12 +1139,8 @@ struct MemorySanitizerVisitor : public InstVisitor { // will get propagated to a void RetVal. if (Call->isTailCall() && Call->getType() != Call->getParent()->getType()) Call->setTailCall(false); - if (isa(&I)) { - // All intrinsics we care about are handled in corresponding visit* - // methods. Add checks for the arguments, mark retval as clean. - visitInstruction(I); - return; - } + + assert(!isa(&I) && "intrinsics are handled elsewhere"); } IRBuilder<> IRB(&I); unsigned ArgOffset = 0; diff --git a/llvm/test/Instrumentation/MemorySanitizer/msan_basic.ll b/llvm/test/Instrumentation/MemorySanitizer/msan_basic.ll index 05cdaa7..a62b600 100644 --- a/llvm/test/Instrumentation/MemorySanitizer/msan_basic.ll +++ b/llvm/test/Instrumentation/MemorySanitizer/msan_basic.ll @@ -351,3 +351,19 @@ define <4 x i32> @ShuffleVector(<4 x i32> %vec, <4 x i32> %vec1) { ; CHECK-NOT: call void @__msan_warning ; CHECK: shufflevector ; CHECK: ret <4 x i32> + +; Test bswap intrinsic instrumentation +define i32 @BSwap(i32 %x) nounwind uwtable readnone { + %y = tail call i32 @llvm.bswap.i32(i32 %x) + ret i32 %y +} + +declare i32 @llvm.bswap.i32(i32) nounwind readnone + +; CHECK: @BSwap +; CHECK-NOT: call void @__msan_warning +; CHECK: @llvm.bswap.i32 +; CHECK-NOT: call void @__msan_warning +; CHECK: @llvm.bswap.i32 +; CHECK-NOT: call void @__msan_warning +; CHECK: ret i32