Skip to content

Commit fa78bc0

Browse files
committed
[𝘀𝗽𝗿] initial version
Created using spr 1.3.6-beta.1
1 parent aebd338 commit fa78bc0

File tree

3 files changed

+42
-16
lines changed

3 files changed

+42
-16
lines changed

llvm/lib/Transforms/Instrumentation/SanitizerCoverage.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1045,10 +1045,8 @@ void ModuleSanitizerCoverage::InjectCoverageAtBlock(Function &F, BasicBlock &BB,
10451045
->setCannotMerge(); // gets the PC using GET_CALLER_PC.
10461046
}
10471047
if (Options.TracePCGuard) {
1048-
auto GuardPtr = IRB.CreateIntToPtr(
1049-
IRB.CreateAdd(IRB.CreatePointerCast(FunctionGuardArray, IntptrTy),
1050-
ConstantInt::get(IntptrTy, Idx * 4)),
1051-
PtrTy);
1048+
auto GuardPtr = IRB.CreateConstInBoundsGEP1_64(
1049+
FunctionGuardArray->getValueType(), FunctionGuardArray, Idx);
10521050
if (Options.GatedCallbacks) {
10531051
Instruction *I = &*IP;
10541052
auto GateBranch = CreateGateBranch(F, FunctionGateCmp, I);

llvm/test/Instrumentation/SanitizerCoverage/cmp-tracing-api-x86_32.ll

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,14 @@ target triple = "i386-unknown-linux-gnu"
77
define i32 @foo() #0 {
88
; CHECK-LABEL: define i32 @foo() comdat {
99
; CHECK-NEXT: entry:
10-
; CHECK-NEXT: call void @__sanitizer_cov_trace_pc_guard(ptr inttoptr (i32 ptrtoint (ptr @__sancov_gen_ to i32) to ptr)) #[[ATTR1:[0-9]+]]
10+
; CHECK-NEXT: call void @__sanitizer_cov_trace_pc_guard(ptr @__sancov_gen_) #[[ATTR1:[0-9]+]]
1111
; CHECK-NEXT: ret i32 0
1212
;
1313
entry:
1414
ret i32 0
1515
}
1616

17+
; UTC_ARGS: --disable
1718
; CHECK-DAG: declare void @__sanitizer_cov_trace_pc_indir(i32)
1819
; CHECK-DAG: declare void @__sanitizer_cov_trace_cmp1(i8 zeroext, i8 zeroext)
1920
; CHECK-DAG: declare void @__sanitizer_cov_trace_cmp2(i16 zeroext, i16 zeroext)
Lines changed: 38 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,23 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 5
12
; RUN: opt < %s -passes='module(sancov-module)' -sanitizer-coverage-level=2 -S | FileCheck %s
23

34
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-S128"
45

56
define i32 @with_dbg(ptr %a, ptr %b) !dbg !3 {
7+
; CHECK-LABEL: define i32 @with_dbg(
8+
; CHECK-SAME: ptr [[A:%.*]], ptr [[B:%.*]]) comdat !dbg [[DBG3:![0-9]+]] {
9+
; CHECK-NEXT: [[ENTRY:.*:]]
10+
; CHECK-NEXT: call void @__sanitizer_cov_trace_pc_guard(ptr @__sancov_gen_) #[[ATTR1:[0-9]+]], !dbg [[DBG6:![0-9]+]]
11+
; CHECK-NEXT: [[TMP1:%.*]] = load i32, ptr [[A]], align 4
12+
; CHECK-NEXT: [[CMP:%.*]] = icmp eq i32 [[TMP1]], 42
13+
; CHECK-NEXT: br i1 [[CMP]], label %[[BB0:.*]], label %[[BB1:.*]]
14+
; CHECK: [[BB0]]:
15+
; CHECK-NEXT: call void @__sanitizer_cov_trace_pc_guard(ptr getelementptr inbounds ([2 x i32], ptr @__sancov_gen_, i64 1)) #[[ATTR1]], !dbg [[DBG7:![0-9]+]]
16+
; CHECK-NEXT: store i32 [[TMP1]], ptr [[B]], align 4
17+
; CHECK-NEXT: br label %[[BB1]]
18+
; CHECK: [[BB1]]:
19+
; CHECK-NEXT: ret i32 [[TMP1]]
20+
;
621
entry:
722
%tmp1 = load i32, ptr %a, align 4
823
%cmp = icmp eq i32 %tmp1, 42
@@ -13,12 +28,22 @@ entry:
1328
1:
1429
ret i32 %tmp1
1530
}
16-
; CHECK-LABEL: @with_dbg
17-
; CHECK-NEXT: entry:
18-
; CHECK: call void @__sanitizer_cov_trace_pc_guard(ptr @__sancov_gen_) #1, !dbg [[DBG1:![0-9]+]]
19-
; CHECK: call void @__sanitizer_cov_trace_pc_guard(ptr inttoptr (i64 add (i64 ptrtoint (ptr @__sancov_gen_ to i64), i64 4) to ptr)) #1, !dbg [[DBG2:![0-9]+]]
2031

2132
define i32 @without_dbg(ptr %a, ptr %b) {
33+
; CHECK-LABEL: define i32 @without_dbg(
34+
; CHECK-SAME: ptr [[A:%.*]], ptr [[B:%.*]]) comdat {
35+
; CHECK-NEXT: [[ENTRY:.*:]]
36+
; CHECK-NEXT: call void @__sanitizer_cov_trace_pc_guard(ptr @__sancov_gen_.1) #[[ATTR1]]
37+
; CHECK-NEXT: [[TMP1:%.*]] = load i32, ptr [[A]], align 4
38+
; CHECK-NEXT: [[CMP:%.*]] = icmp eq i32 [[TMP1]], 42
39+
; CHECK-NEXT: br i1 [[CMP]], label %[[BB0:.*]], label %[[BB1:.*]]
40+
; CHECK: [[BB0]]:
41+
; CHECK-NEXT: call void @__sanitizer_cov_trace_pc_guard(ptr getelementptr inbounds ([2 x i32], ptr @__sancov_gen_.1, i64 1)) #[[ATTR1]]
42+
; CHECK-NEXT: store i32 [[TMP1]], ptr [[B]], align 4
43+
; CHECK-NEXT: br label %[[BB1]]
44+
; CHECK: [[BB1]]:
45+
; CHECK-NEXT: ret i32 [[TMP1]]
46+
;
2247
entry:
2348
%tmp1 = load i32, ptr %a, align 4
2449
%cmp = icmp eq i32 %tmp1, 42
@@ -29,10 +54,6 @@ entry:
2954
1:
3055
ret i32 %tmp1
3156
}
32-
; CHECK-LABEL: @without_dbg
33-
; CHECK-NEXT: entry:
34-
; CHECK: call void @__sanitizer_cov_trace_pc_guard(ptr @__sancov_gen_.1) #1
35-
; CHECK: call void @__sanitizer_cov_trace_pc_guard(ptr inttoptr (i64 add (i64 ptrtoint (ptr @__sancov_gen_.1 to i64), i64 4) to ptr)) #1
3657

3758
!llvm.dbg.cu = !{!0}
3859
!llvm.module.flags = !{!2}
@@ -45,6 +66,12 @@ entry:
4566
!5 = !{}
4667
!6 = !DILocation(line: 192, scope: !3)
4768
!7 = !DILocation(line: 0, scope: !3)
48-
49-
; CHECK: [[DBG1]] = !DILocation(line: 192, scope: !3)
50-
; CHECK: [[DBG2]] = !DILocation(line: 0, scope: !3)
69+
;.
70+
; CHECK: [[META0:![0-9]+]] = distinct !DICompileUnit(language: DW_LANG_C89, file: [[META1:![0-9]+]], isOptimized: true, runtimeVersion: 0, emissionKind: LineTablesOnly, splitDebugInlining: false, nameTableKind: None)
71+
; CHECK: [[META1]] = !DIFile(filename: "foo.c", directory: "")
72+
; CHECK: [[DBG3]] = distinct !DISubprogram(name: "foo", scope: [[META1]], file: [[META1]], line: 190, type: [[META4:![0-9]+]], scopeLine: 192, flags: DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagLocalToUnit | DISPFlagDefinition | DISPFlagOptimized, unit: [[META0]])
73+
; CHECK: [[META4]] = !DISubroutineType(types: [[META5:![0-9]+]])
74+
; CHECK: [[META5]] = !{}
75+
; CHECK: [[DBG6]] = !DILocation(line: 192, scope: [[DBG3]])
76+
; CHECK: [[DBG7]] = !DILocation(line: 0, scope: [[DBG3]])
77+
;.

0 commit comments

Comments
 (0)