Skip to content

Commit 4cf53cd

Browse files
authored
[msan] Fix "Add optional flag to improve instrumentation of disjoint OR (#145990)" (#146799)
The "V1" and "V2" values were already NOT'ed, hence the calculation of disjoint OR in #145990 was incorrect. This patch fixes the issue, with some refactoring and renaming of variables.
1 parent 922dde3 commit 4cf53cd

File tree

2 files changed

+12
-7
lines changed

2 files changed

+12
-7
lines changed

llvm/lib/Transforms/Instrumentation/MemorySanitizer.cpp

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2512,20 +2512,25 @@ struct MemorySanitizerVisitor : public InstVisitor<MemorySanitizerVisitor> {
25122512
// S = S | (V1 & V2)
25132513
Value *S1 = getShadow(&I, 0);
25142514
Value *S2 = getShadow(&I, 1);
2515-
Value *V1 = IRB.CreateNot(I.getOperand(0));
2516-
Value *V2 = IRB.CreateNot(I.getOperand(1));
2515+
Value *V1 = I.getOperand(0);
2516+
Value *V2 = I.getOperand(1);
25172517
if (V1->getType() != S1->getType()) {
25182518
V1 = IRB.CreateIntCast(V1, S1->getType(), false);
25192519
V2 = IRB.CreateIntCast(V2, S2->getType(), false);
25202520
}
2521+
2522+
Value *NotV1 = IRB.CreateNot(V1);
2523+
Value *NotV2 = IRB.CreateNot(V2);
2524+
25212525
Value *S1S2 = IRB.CreateAnd(S1, S2);
2522-
Value *V1S2 = IRB.CreateAnd(V1, S2);
2523-
Value *S1V2 = IRB.CreateAnd(S1, V2);
2526+
Value *S2NotV1 = IRB.CreateAnd(NotV1, S2);
2527+
Value *S1NotV2 = IRB.CreateAnd(S1, NotV2);
2528+
2529+
Value *S = IRB.CreateOr({S1S2, S2NotV1, S1NotV2});
25242530

2525-
Value *S = IRB.CreateOr({S1S2, V1S2, S1V2});
25262531
if (ClPreciseDisjointOr && cast<PossiblyDisjointInst>(&I)->isDisjoint()) {
25272532
Value *V1V2 = IRB.CreateAnd(V1, V2);
2528-
S = IRB.CreateOr({S, V1V2});
2533+
S = IRB.CreateOr(S, V1V2, "_ms_disjoint");
25292534
}
25302535

25312536
setShadow(&I, S);

llvm/test/Instrumentation/MemorySanitizer/or.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ define i8 @test_disjoint_or(i8 %a, i8 %b) sanitize_memory {
4545
; CHECK-IMPRECISE: [[C:%.*]] = or disjoint i8 [[A]], [[B]]
4646
; CHECK-IMPRECISE-NEXT: store i8 [[TMP11]], ptr @__msan_retval_tls, align 8
4747
;
48-
; CHECK-PRECISE: [[TMP10:%.*]] = and i8 [[TMP3]], [[TMP4]]
48+
; CHECK-PRECISE: [[TMP10:%.*]] = and i8 [[A]], [[B]]
4949
; CHECK-PRECISE-NEXT: [[TMP12:%.*]] = or i8 [[TMP11]], [[TMP10]]
5050
; CHECK-PRECISE-NEXT: [[C:%.*]] = or disjoint i8 [[A]], [[B]]
5151
; CHECK-PRECISE-NEXT: store i8 [[TMP12]], ptr @__msan_retval_tls, align 8

0 commit comments

Comments
 (0)