1 | // Test that custom memmove implementations instrumented by HWASan do not cause |
2 | // false positives. |
3 | |
4 | // RUN: %clang_hwasan %s -o %t |
5 | // RUN: %run %t |
6 | |
7 | #include <assert.h> |
8 | #include <sanitizer/hwasan_interface.h> |
9 | #include <stdlib.h> |
10 | |
11 | void *memmove(void *Dest, const void *Src, size_t N) { |
12 | char *Tmp = (char *)malloc(size: N); |
13 | char *D = (char *)Dest; |
14 | const char *S = (const char *)Src; |
15 | |
16 | for (size_t I = 0; I < N; ++I) |
17 | Tmp[I] = S[I]; |
18 | for (size_t I = 0; I < N; ++I) |
19 | D[I] = Tmp[I]; |
20 | |
21 | free(ptr: Tmp); |
22 | return Dest; |
23 | } |
24 | |
25 | int main() { |
26 | __hwasan_enable_allocator_tagging(); |
27 | |
28 | const size_t BufSize = 64; |
29 | char *Buf = (char *)malloc(size: BufSize); |
30 | |
31 | for (size_t I = 0; I < BufSize; ++I) |
32 | Buf[I] = I; |
33 | memmove(Dest: Buf + BufSize / 2, Src: Buf, N: BufSize / 2); |
34 | for (size_t I = 0; I < BufSize; ++I) |
35 | assert(Buf[I] == I % (BufSize / 2)); |
36 | |
37 | free(ptr: Buf); |
38 | return 0; |
39 | } |
40 | |