[PATCH] D131845: [MSAN] Correct shadow type for atomicrmw instrumentation

Keno Fischer via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sat Aug 13 17:35:20 PDT 2022


loladiro created this revision.
loladiro added a reviewer: eugenis.
Herald added subscribers: Enna1, hiraditya.
Herald added a project: All.
loladiro requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

We were passing the type of `Val` to `getShadowOriginPtr`, rather
than the type of `Val`'s shadow resulting in broken IR. The fix
is simple.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D131845

Files:
  llvm/lib/Transforms/Instrumentation/MemorySanitizer.cpp
  llvm/test/Instrumentation/MemorySanitizer/atomics.ll


Index: llvm/test/Instrumentation/MemorySanitizer/atomics.ll
===================================================================
--- llvm/test/Instrumentation/MemorySanitizer/atomics.ll
+++ llvm/test/Instrumentation/MemorySanitizer/atomics.ll
@@ -22,6 +22,20 @@
 ; CHECK: store i32 0, {{.*}} @__msan_retval_tls
 ; CHECK: ret i32
 
+; atomicrmw xchg: store clean shadow, return clean shadow
+
+define i32* @AtomicRmwXchgPtr(i32** %p, i32* %x) sanitize_memory {
+entry:
+  %0 = atomicrmw xchg i32** %p, i32* %x seq_cst
+  ret i32* %0
+}
+
+; CHECK-LABEL: @AtomicRmwXchg
+; CHECK: store i32 0,
+; CHECK: atomicrmw xchg {{.*}} seq_cst
+; CHECK: store i32 0, {{.*}} @__msan_retval_tls
+; CHECK: ret i32
+
 
 ; atomicrmw max: exactly the same as above
 
Index: llvm/lib/Transforms/Instrumentation/MemorySanitizer.cpp
===================================================================
--- llvm/lib/Transforms/Instrumentation/MemorySanitizer.cpp
+++ llvm/lib/Transforms/Instrumentation/MemorySanitizer.cpp
@@ -1949,7 +1949,7 @@
     IRBuilder<> IRB(&I);
     Value *Addr = I.getOperand(0);
     Value *Val = I.getOperand(1);
-    Value *ShadowPtr = getShadowOriginPtr(Addr, IRB, Val->getType(), Align(1),
+    Value *ShadowPtr = getShadowOriginPtr(Addr, IRB, getShadowTy(Val), Align(1),
                                           /*isStore*/ true)
                            .first;
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D131845.452462.patch
Type: text/x-patch
Size: 1378 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220814/8648eef6/attachment.bin>


More information about the llvm-commits mailing list