[OptTable] Fix typo VALUE => VALUES (NFCI) (#121523)
[llvm-project.git] / compiler-rt / test / hwasan / TestCases / custom-memmove.c
blob7b15e06234debd63357146ce15952a357a7da719
1 // Test that custom memmove implementations instrumented by HWASan do not cause
2 // false positives.
4 // RUN: %clang_hwasan %s -o %t
5 // RUN: %run %t
7 #include <assert.h>
8 #include <sanitizer/hwasan_interface.h>
9 #include <stdlib.h>
11 void *memmove(void *Dest, const void *Src, size_t N) {
12 char *Tmp = (char *)malloc(N);
13 char *D = (char *)Dest;
14 const char *S = (const char *)Src;
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];
21 free(Tmp);
22 return Dest;
25 int main() {
26 __hwasan_enable_allocator_tagging();
28 const size_t BufSize = 64;
29 char *Buf = (char *)malloc(BufSize);
31 for (size_t I = 0; I < BufSize; ++I)
32 Buf[I] = I;
33 memmove(Buf + BufSize / 2, Buf, BufSize / 2);
34 for (size_t I = 0; I < BufSize; ++I)
35 assert(Buf[I] == I % (BufSize / 2));
37 free(Buf);
38 return 0;