From 7d5328c5df19429c6526df1e4106d58e470db617 Mon Sep 17 00:00:00 2001 From: Peter Hawkins Date: Wed, 27 Jan 2021 06:40:40 -0800 Subject: [PATCH] [XLA:CPU] When built with MSAN, unpoison outfed buffers to suppress false-positive MSAN warnings. PiperOrigin-RevId: 354080879 Change-Id: If5b257d2a0fd992b79806054b43eef4b77f66d72 --- tensorflow/compiler/xla/service/cpu/ir_emitter.cc | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/tensorflow/compiler/xla/service/cpu/ir_emitter.cc b/tensorflow/compiler/xla/service/cpu/ir_emitter.cc index 7179c5a00ba..445392cf4a6 100644 --- a/tensorflow/compiler/xla/service/cpu/ir_emitter.cc +++ b/tensorflow/compiler/xla/service/cpu/ir_emitter.cc @@ -487,6 +487,17 @@ Status IrEmitter::EmitXfeedTransfer(XfeedKind kind, const Shape& shape, MemCpy(acquired_pointer, /*DstAlign=*/llvm::Align(1), program_buffer_address, /*SrcAlign=*/llvm::Align(1), length_32); + if (emit_code_for_msan_) { + // Mark the outfed data as initialized for msan. The buffer gets read by + // the host code, which might be msan-instrumented. + // TODO(b/66051036): Run the msan instrumentation pass instead. + const llvm::DataLayout& dl = module_->getDataLayout(); + llvm::Type* intptr_type = b_.getIntPtrTy(dl); + EmitCallToFunc( + "__msan_unpoison", + {acquired_pointer, llvm::ConstantInt::get(intptr_type, length)}, + b_.getVoidTy()); + } } const char* release_func_name =