30 lines · cpp
1// RUN: %clangxx_hwasan %s -o %t && not %run %t 2>&1 | FileCheck %s2 3#include <stdio.h>4#include <stdlib.h>5 6#include <sanitizer/hwasan_interface.h>7 8__attribute__((no_sanitize("hwaddress"))) extern "C" void callback(const char *msg) {9 fprintf(stderr, "== error start\n%s\n== error end\n", msg);10}11 12int main() {13 __hwasan_enable_allocator_tagging();14 __hwasan_set_error_report_callback(&callback);15 char *volatile p = (char *)malloc(16);16 p[16] = 1;17 free(p);18 // CHECK: ERROR: HWAddressSanitizer:19 // CHECK: WRITE of size 1 at20 // CHECK: allocated by thread {{.*}} here:21 // CHECK: Memory tags around the buggy address22 23 // CHECK: == error start24 // CHECK: ERROR: HWAddressSanitizer:25 // CHECK: WRITE of size 1 at26 // CHECK: allocated by thread {{.*}} here:27 // CHECK: Memory tags around the buggy address28 // CHECK: == error end29}30