[llvm] efc8f33 - [msan] Set cmpxchg shadow precisely

Jianzhou Zhao via llvm-commits llvm-commits at lists.llvm.org
Fri Feb 19 12:24:03 PST 2021


Author: Jianzhou Zhao
Date: 2021-02-19T20:23:23Z
New Revision: efc8f3311b57ce438500d8a0908e6c7cf6c9f551

URL: https://github.com/llvm/llvm-project/commit/efc8f3311b57ce438500d8a0908e6c7cf6c9f551
DIFF: https://github.com/llvm/llvm-project/commit/efc8f3311b57ce438500d8a0908e6c7cf6c9f551.diff

LOG: [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

Added: 
    

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

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Transforms/Instrumentation/MemorySanitizer.cpp b/llvm/lib/Transforms/Instrumentation/MemorySanitizer.cpp
index f484ff0a98c8..64574a6aa231 100644
--- a/llvm/lib/Transforms/Instrumentation/MemorySanitizer.cpp
+++ b/llvm/lib/Transforms/Instrumentation/MemorySanitizer.cpp
@@ -1948,7 +1948,8 @@ struct MemorySanitizerVisitor : public InstVisitor<MemorySanitizerVisitor> {
 
     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<MemorySanitizerVisitor> {
     // The other argument can potentially be uninitialized, but we can not
     // detect this situation reliably without possible false positives.
     if (isa<AtomicCmpXchgInst>(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/llvm/test/Instrumentation/MemorySanitizer/atomics.ll b/llvm/test/Instrumentation/MemorySanitizer/atomics.ll
index 36afb91a40bf..f6d326e52eab 100644
--- a/llvm/test/Instrumentation/MemorySanitizer/atomics.ll
+++ b/llvm/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


        


More information about the llvm-commits mailing list