Skip to content

Commit

Permalink
[MSAN] Correct shadow type for atomicrmw instrumentation
Browse files Browse the repository at this point in the history
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.

Reviewed By: eugenis

Differential Revision: https://reviews.llvm.org/D131845
  • Loading branch information
Keno committed Aug 24, 2022
1 parent 4c51142 commit 5739d29
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion llvm/lib/Transforms/Instrumentation/MemorySanitizer.cpp
Expand Up @@ -1949,7 +1949,7 @@ struct MemorySanitizerVisitor : public InstVisitor<MemorySanitizerVisitor> {
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;

Expand Down
14 changes: 14 additions & 0 deletions llvm/test/Instrumentation/MemorySanitizer/atomics.ll
Expand Up @@ -22,6 +22,20 @@ entry:
; CHECK: store i32 0, {{.*}} @__msan_retval_tls
; CHECK: ret i32

; atomicrmw xchg ptr: exactly the same as above

define i32* @AtomicRmwXchgPtr(i32** %p, i32* %x) sanitize_memory {
entry:
%0 = atomicrmw xchg i32** %p, i32* %x seq_cst
ret i32* %0
}

; CHECK-LABEL: @AtomicRmwXchgPtr
; CHECK: store i64 0,
; CHECK: atomicrmw xchg {{.*}} seq_cst
; CHECK: store i64 0, {{.*}} @__msan_retval_tls
; CHECK: ret i32*


; atomicrmw max: exactly the same as above

Expand Down

0 comments on commit 5739d29

Please sign in to comment.