1// Tests -fsanitize-coverage=trace-pc,trace-loads,trace-stores
2//
3// REQUIRES: has_sancovcc,stable-runtime,x86_64
4//
5// RUN: %clangxx -O0 %s -fsanitize-coverage=trace-pc,trace-loads,trace-stores -o %t
6// RUN: %run %t 2>&1 | FileCheck %s
7
8#include <stdint.h>
9#include <stdio.h>
10
11extern "C" {
12void __sanitizer_cov_load1(uint8_t *addr) { printf(format: "load1: %p\n", addr); }
13void __sanitizer_cov_load2(uint16_t *addr) { printf(format: "load2: %p\n", addr); }
14void __sanitizer_cov_load4(uint32_t *addr) { printf(format: "load4: %p\n", addr); }
15void __sanitizer_cov_load8(uint64_t *addr) { printf(format: "load8: %p\n", addr); }
16void __sanitizer_cov_load16(__int128 *addr) { printf(format: "load16: %p\n", addr); }
17
18void __sanitizer_cov_store1(uint8_t *addr) { printf(format: "store1: %p\n", addr); }
19void __sanitizer_cov_store2(uint16_t *addr) { printf(format: "store2: %p\n", addr); }
20void __sanitizer_cov_store4(uint32_t *addr) { printf(format: "store4: %p\n", addr); }
21void __sanitizer_cov_store8(uint64_t *addr) { printf(format: "store8: %p\n", addr); }
22void __sanitizer_cov_store16(__int128 *addr) { printf(format: "store16: %p\n", addr); }
23}
24
25uint8_t var1;
26uint16_t var2;
27uint32_t var4;
28uint64_t var8;
29__int128 var16;
30static volatile int sink;
31
32int main() {
33 printf(format: "var1: %p\n", &var1);
34 sink = var1;
35 var1 = 42;
36 // CHECK: var1: [[ADDR:0x.*]]
37 // CHECK: load1: [[ADDR]]
38 // CHECK: store1: [[ADDR]]
39
40 printf(format: "var2: %p\n", &var2);
41 sink = var2;
42 var2 = 42;
43 // CHECK: var2: [[ADDR:0x.*]]
44 // CHECK: load2: [[ADDR]]
45 // CHECK: store2: [[ADDR]]
46
47 printf(format: "var4: %p\n", &var4);
48 sink = var4;
49 var4 = 42;
50 // CHECK: var4: [[ADDR:0x.*]]
51 // CHECK: load4: [[ADDR]]
52 // CHECK: store4: [[ADDR]]
53
54 printf(format: "var8: %p\n", &var8);
55 sink = var8;
56 var8 = 42;
57 // CHECK: var8: [[ADDR:0x.*]]
58 // CHECK: load8: [[ADDR]]
59 // CHECK: store8: [[ADDR]]
60
61 printf(format: "var16: %p\n", &var16);
62 sink = var16;
63 var16 = 42;
64 // CHECK: var16: [[ADDR:0x.*]]
65 // CHECK: load16: [[ADDR]]
66 // CHECK: store16: [[ADDR]]
67 printf(format: "PASS\n");
68}
69

source code of compiler-rt/test/sanitizer_common/TestCases/sanitizer_coverage_trace_loads_stores.cpp