[llvm] [msan] Unpoison indirect outputs for userspace when -msan-handle-asm-conservative is specified (PR #77393)

Fangrui Song via llvm-commits llvm-commits at lists.llvm.org
Thu Jan 18 00:23:23 PST 2024


================
@@ -4557,7 +4561,13 @@ struct MemorySanitizerVisitor : public InstVisitor<MemorySanitizerVisitor> {
       return;
     Value *SizeVal =
       IRB.CreateTypeSize(MS.IntptrTy, DL.getTypeStoreSize(ElemTy));
-    IRB.CreateCall(MS.MsanInstrumentAsmStoreFn, {Operand, SizeVal});
+    if (MS.CompileKernel) {
+      IRB.CreateCall(MS.MsanInstrumentAsmStoreFn, {Operand, SizeVal});
+    } else {
+      auto [ShadowPtr, _] =
+          getShadowOriginPtrUserspace(Operand, IRB, IRB.getInt8Ty(), Align(1));
+      IRB.CreateAlignedStore(getCleanShadow(ElemTy), ShadowPtr, Align(1));
----------------
MaskRay wrote:

ElemTy` utilizes `elementtype` (`ptr elementtype(i32) @id1` => i32, which does not encode the alignment).
An unspecified alignment uses the default, `ElemTy`'s alignment, which is 4 in the i32 case.
However, if the element type is actually unaligned, `CreateStore` could cause a shadow misalignment issue on certain architectures using `-mstrict-align`.

The tests specifically write `, align 1`

https://github.com/llvm/llvm-project/pull/77393


More information about the llvm-commits mailing list