Skip to content

Commit 08032e7

Browse files
pratyaivitalybuka
authored andcommitted
[SanitizerCoverage] Replace the unconditional store with a load, then a conditional store.
Reviewers: vitalybuka, kcc Subscribers: hiraditya, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D79392
1 parent 898f74c commit 08032e7

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

llvm/lib/Transforms/Instrumentation/SanitizerCoverage.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -945,7 +945,12 @@ void ModuleSanitizerCoverage::InjectCoverageAtBlock(Function &F, BasicBlock &BB,
945945
auto FlagPtr = IRB.CreateGEP(
946946
FunctionBoolArray->getValueType(), FunctionBoolArray,
947947
{ConstantInt::get(IntptrTy, 0), ConstantInt::get(IntptrTy, Idx)});
948-
auto Store = IRB.CreateStore(ConstantInt::getTrue(Int1Ty), FlagPtr);
948+
auto Load = IRB.CreateLoad(Int1Ty, FlagPtr);
949+
auto ThenTerm =
950+
SplitBlockAndInsertIfThen(IRB.CreateIsNull(Load), &*IP, false);
951+
IRBuilder<> ThenIRB(ThenTerm);
952+
auto Store = ThenIRB.CreateStore(ConstantInt::getTrue(Int1Ty), FlagPtr);
953+
SetNoSanitizeMetadata(Load);
949954
SetNoSanitizeMetadata(Store);
950955
}
951956
if (Options.StackDepth && IsEntryBB && !IsLeafFunc) {
Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,23 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
12
; Test -sanitizer-coverage-inline-bool-flag=1
23
; RUN: opt < %s -sancov -sanitizer-coverage-level=1 -sanitizer-coverage-inline-bool-flag=1 -S | FileCheck %s
34
; RUN: opt < %s -passes='module(sancov-module)' -sanitizer-coverage-level=1 -sanitizer-coverage-inline-bool-flag=1 -S | FileCheck %s
45

56
target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64"
67
target triple = "x86_64-unknown-linux-gnu"
78
define void @foo() {
9+
; CHECK-LABEL: @foo(
10+
; CHECK-NEXT: entry:
11+
; CHECK-NEXT: [[TMP0:%.*]] = load i1, i1* getelementptr inbounds ([1 x i1], [1 x i1]* @__sancov_gen_, i64 0, i64 0), align 1, !nosanitize !1
12+
; CHECK-NEXT: [[TMP1:%.*]] = icmp eq i1 [[TMP0]], false
13+
; CHECK-NEXT: br i1 [[TMP1]], label [[TMP2:%.*]], label [[TMP3:%.*]]
14+
; CHECK: 2:
15+
; CHECK-NEXT: store i1 true, i1* getelementptr inbounds ([1 x i1], [1 x i1]* @__sancov_gen_, i64 0, i64 0), align 1, !nosanitize !1
16+
; CHECK-NEXT: br label [[TMP3]]
17+
; CHECK: 3:
18+
; CHECK-NEXT: ret void
19+
;
820
entry:
9-
; CHECK: @__sancov_gen_ = private global [1 x i1] zeroinitializer, section "__sancov_bools", comdat($foo), align 1, !associated !0
10-
; CHECK: store i1 true, i1* getelementptr inbounds ([1 x i1], [1 x i1]* @__sancov_gen_, i64 0, i64 0), align 1, !nosanitize !1
1121
ret void
1222
}
1323
; CHECK: call void @__sanitizer_cov_bool_flag_init(i1* bitcast (i1** @__start___sancov_bools to i1*), i1* bitcast (i1** @__stop___sancov_bools to i1*))

0 commit comments

Comments
 (0)