Revert "[lldb][test] Remove compiler version check and use regex" (#124101)
[llvm-project.git] / compiler-rt / test / hwasan / TestCases / bcmp.cpp
blob9b21bba56b1beea9859f142b1af8137b57c3b891
1 // RUN: %clangxx_hwasan -O0 %s -o %t && not %run %t 2>&1 | FileCheck %s
2 // RUN: %clangxx_hwasan -O1 %s -o %t && not %run %t 2>&1 | FileCheck %s
3 // RUN: %clangxx_hwasan -O2 %s -o %t && not %run %t 2>&1 | FileCheck %s
4 // RUN: %clangxx_hwasan -O3 %s -o %t && not %run %t 2>&1 | FileCheck %s
5 // REQUIRES: !android
7 #include <assert.h>
8 #include <sanitizer/hwasan_interface.h>
9 #include <stdlib.h>
10 #include <string.h>
11 #include <unistd.h>
13 __attribute__((no_sanitize("hwaddress"))) void
14 ForceCallInterceptor(void *p, const void *a, size_t size) {
15 assert(bcmp(p, a, size) == 0);
18 int main(int argc, char **argv) {
19 __hwasan_enable_allocator_tagging();
20 char a[] = {static_cast<char>(argc), 2, 3, 4};
21 int size = sizeof(a);
22 char *p = (char *)malloc(size);
23 memcpy(p, a, size);
24 free(p);
25 ForceCallInterceptor(p, a, size);
26 return 0;
27 // CHECK: HWAddressSanitizer: tag-mismatch on address
28 // CHECK: READ of size 4
29 // CHECK: #{{[[:digit:]]+}} 0x{{[[:xdigit:]]+}} in main {{.*}}bcmp.cpp:[[@LINE-4]]
30 // CHECK: Cause: use-after-free
31 // CHECK: freed by thread
32 // CHECK: #{{[[:digit:]]+}} 0x{{[[:xdigit:]]+}} in main {{.*}}bcmp.cpp:[[@LINE-8]]
33 // CHECK: previously allocated by thread
34 // CHECK: #{{[[:digit:]]+}} 0x{{[[:xdigit:]]+}} in main {{.*}}bcmp.cpp:[[@LINE-12]]