summaryrefslogtreecommitdiff
path: root/test/hwasan/TestCases/use-after-free.cc
blob: a4433b8de7b83b88c9073c705df2248d3dae8a01 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
// RUN: %clangxx_hwasan -O0 %s -o %t && not %run %t 2>&1 | FileCheck %s --check-prefix=CHECK
// RUN: %clangxx_hwasan -O1 %s -o %t && not %run %t 2>&1 | FileCheck %s --check-prefix=CHECK
// RUN: %clangxx_hwasan -O2 %s -o %t && not %run %t 2>&1 | FileCheck %s --check-prefix=CHECK
// RUN: %clangxx_hwasan -O3 %s -o %t && not %run %t 2>&1 | FileCheck %s --check-prefix=CHECK
// REQUIRES: stable-runtime

#include <stdlib.h>
#include <sanitizer/hwasan_interface.h>

int main() {
  __hwasan_enable_allocator_tagging();
  char *x = (char*)malloc(10);
  free(x);
  __hwasan_disable_allocator_tagging();
  return x[5];
  // CHECK: READ of size 1 at
  // CHECK: #0 {{.*}} in main {{.*}}use-after-free.cc:15

  // CHECK: freed here:
  // CHECK: #0 {{.*}} in free {{.*}}hwasan_interceptors.cc
  // CHECK: #1 {{.*}} in main {{.*}}use-after-free.cc:13

  // CHECK: previously allocated here:
  // CHECK: #0 {{.*}} in __interceptor_malloc {{.*}}hwasan_interceptors.cc
  // CHECK: #1 {{.*}} in main {{.*}}use-after-free.cc:12

  // CHECK: SUMMARY: HWAddressSanitizer: tag-mismatch {{.*}} in main
}