1// RUN: %clangxx_hwasan %s -o %t && not %run %t 2>&1 | FileCheck %s
2
3#include <sanitizer/hwasan_interface.h>
4
5#include <stdio.h>
6#include <stdlib.h>
7#include <sys/mman.h>
8#include <unistd.h>
9
10int main(int argc, char **argv) {
11 const size_t kPS = sysconf(_SC_PAGESIZE);
12
13 void *r = nullptr;
14 int res = posix_memalign(memptr: &r, alignment: kPS, size: 2 * kPS);
15 if (res) {
16 perror(s: "Failed to mmap: ");
17 abort();
18 }
19
20 r = __hwasan_tag_pointer(p: r, tag: 0);
21 __hwasan_tag_memory(p: r, tag: 1, size: 2 * kPS);
22
23 // Disable access to the page just after tag-mismatch report address.
24 res = mprotect(addr: (char*)r + kPS, len: kPS, PROT_NONE);
25 if (res) {
26 perror(s: "Failed to mprotect: ");
27 abort();
28 }
29
30 // Trigger tag-mismatch report.
31 return *((char*)r + kPS - 1);
32}
33
34// CHECK: ERROR: HWAddressSanitizer: tag-mismatch on address
35// CHECK: Memory tags around the buggy address
36// CHECK: Tags for short granules around
37
38// Check that report is complete.
39// CHECK: SUMMARY: HWAddressSanitizer: tag-mismatch {{.*}} in main
40

source code of compiler-rt/test/hwasan/TestCases/report-unmapped.cpp