1 // RUN: %clang_scudo %s -o %t
2 // RUN: SCUDO_OPTIONS=DeallocationTypeMismatch=1 not %run %t mallocdel   2>&1 | FileCheck %s
3 // RUN: SCUDO_OPTIONS=DeallocationTypeMismatch=0     %run %t mallocdel   2>&1
4 // RUN: SCUDO_OPTIONS=DeallocationTypeMismatch=1 not %run %t newfree     2>&1 | FileCheck %s
5 // RUN: SCUDO_OPTIONS=DeallocationTypeMismatch=0     %run %t newfree     2>&1
6 // RUN: SCUDO_OPTIONS=DeallocationTypeMismatch=1 not %run %t memaligndel 2>&1 | FileCheck %s
7 // RUN: SCUDO_OPTIONS=DeallocationTypeMismatch=0     %run %t memaligndel 2>&1
8 
9 // Tests that type mismatches between allocation and deallocation functions are
10 // caught when the related option is set.
11 
12 #include <assert.h>
13 #include <malloc.h>
14 #include <stdlib.h>
15 #include <string.h>
16 
17 int main(int argc, char **argv)
18 {
19   assert(argc == 2);
20   if (!strcmp(argv[1], "mallocdel")) {
21     int *p = (int *)malloc(16);
22     assert(p);
23     delete p;
24   }
25   if (!strcmp(argv[1], "newfree")) {
26     int *p = new int;
27     assert(p);
28     free((void *)p);
29   }
30   if (!strcmp(argv[1], "memaligndel")) {
31     int *p = (int *)memalign(16, 16);
32     assert(p);
33     delete p;
34   }
35   return 0;
36 }
37 
38 // CHECK: ERROR: allocation type mismatch on address
39