Revert "[lldb][test] Remove compiler version check and use regex" (#124101)
[llvm-project.git] / compiler-rt / test / hwasan / TestCases / report-unmapped.cpp
blobc00a615f7d5254f30ab7a5d9621aa3915900253c
1 // RUN: %clangxx_hwasan %s -o %t && not %run %t 2>&1 | FileCheck %s
3 #include <sanitizer/hwasan_interface.h>
5 #include <stdio.h>
6 #include <stdlib.h>
7 #include <sys/mman.h>
8 #include <unistd.h>
10 int main(int argc, char **argv) {
11 const size_t kPS = sysconf(_SC_PAGESIZE);
13 void *r = nullptr;
14 int res = posix_memalign(&r, kPS, 2 * kPS);
15 if (res) {
16 perror("Failed to mmap: ");
17 abort();
20 r = __hwasan_tag_pointer(r, 0);
21 __hwasan_tag_memory(r, 1, 2 * kPS);
23 // Disable access to the page just after tag-mismatch report address.
24 res = mprotect((char*)r + kPS, kPS, PROT_NONE);
25 if (res) {
26 perror("Failed to mprotect: ");
27 abort();
30 // Trigger tag-mismatch report.
31 return *((char*)r + kPS - 1);
34 // CHECK: ERROR: HWAddressSanitizer: tag-mismatch on address
35 // CHECK: Memory tags around the buggy address
36 // CHECK: Tags for short granules around
38 // Check that report is complete.
39 // CHECK: SUMMARY: HWAddressSanitizer: tag-mismatch {{.*}} in main