From fbcfd3cb70a60c103a9e89ea88c55eb5deced2ac Mon Sep 17 00:00:00 2001 From: Jianzhou Zhao Date: Fri, 19 Feb 2021 04:37:49 +0000 Subject: [PATCH] [msan] Set cmpxchg shadow precisely In terms of https://llvm.org/docs/LangRef.html#cmpxchg-instruction, the return type of chmpxchg is a pair {ty, i1}, while I think we only wanted to set the shadow for the address 0th op, and it has type ty. Reviewed-by: eugenis Differential Revision: https://reviews.llvm.org/D97029 --- lib/Transforms/Instrumentation/MemorySanitizer.cpp | 7 ++++--- test/Instrumentation/MemorySanitizer/atomics.ll | 4 ++-- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/lib/Transforms/Instrumentation/MemorySanitizer.cpp b/lib/Transforms/Instrumentation/MemorySanitizer.cpp index f484ff0a98c..64574a6aa23 100644 --- a/lib/Transforms/Instrumentation/MemorySanitizer.cpp +++ b/lib/Transforms/Instrumentation/MemorySanitizer.cpp @@ -1948,7 +1948,8 @@ struct MemorySanitizerVisitor : public InstVisitor { IRBuilder<> IRB(&I); Value *Addr = I.getOperand(0); - Value *ShadowPtr = getShadowOriginPtr(Addr, IRB, I.getType(), Align(1), + Value *Val = I.getOperand(1); + Value *ShadowPtr = getShadowOriginPtr(Addr, IRB, Val->getType(), Align(1), /*isStore*/ true) .first; @@ -1959,9 +1960,9 @@ struct MemorySanitizerVisitor : public InstVisitor { // The other argument can potentially be uninitialized, but we can not // detect this situation reliably without possible false positives. if (isa(I)) - insertShadowCheck(I.getOperand(1), &I); + insertShadowCheck(Val, &I); - IRB.CreateStore(getCleanShadow(&I), ShadowPtr); + IRB.CreateStore(getCleanShadow(Val), ShadowPtr); setShadow(&I, getCleanShadow(&I)); setOrigin(&I, getCleanOrigin()); diff --git a/test/Instrumentation/MemorySanitizer/atomics.ll b/test/Instrumentation/MemorySanitizer/atomics.ll index 36afb91a40b..f6d326e52ea 100644 --- a/test/Instrumentation/MemorySanitizer/atomics.ll +++ b/test/Instrumentation/MemorySanitizer/atomics.ll @@ -51,7 +51,7 @@ entry: } ; CHECK-LABEL: @Cmpxchg -; CHECK: store { i32, i1 } zeroinitializer, +; CHECK: store i32 0, ; CHECK: icmp ; CHECK: br ; CHECK: @__msan_warning_with_origin @@ -70,7 +70,7 @@ entry: } ; CHECK-LABEL: @CmpxchgMonotonic -; CHECK: store { i32, i1 } zeroinitializer, +; CHECK: store i32 0, ; CHECK: icmp ; CHECK: br ; CHECK: @__msan_warning_with_origin