xref: /llvm-project/compiler-rt/test/scudo/mismatch.cpp (revision f7c5c0d87b8ae5e55006fd3a31994cd68d64f102)
1*f7c5c0d8SMitch Phillips // RUN: %clangxx_scudo %s -o %t
2*f7c5c0d8SMitch Phillips // RUN: %env_scudo_opts=DeallocationTypeMismatch=1 not %run %t mallocdel 2>&1 | FileCheck --check-prefix=CHECK-dealloc %s
3*f7c5c0d8SMitch Phillips // RUN: %env_scudo_opts=DeallocationTypeMismatch=0     %run %t mallocdel 2>&1
4*f7c5c0d8SMitch Phillips // RUN: %env_scudo_opts=DeallocationTypeMismatch=1 not %run %t newfree   2>&1 | FileCheck --check-prefix=CHECK-dealloc %s
5*f7c5c0d8SMitch Phillips // RUN: %env_scudo_opts=DeallocationTypeMismatch=0     %run %t newfree   2>&1
6*f7c5c0d8SMitch Phillips 
7*f7c5c0d8SMitch Phillips // Tests that type mismatches between allocation and deallocation functions are
8*f7c5c0d8SMitch Phillips // caught when the related option is set.
9*f7c5c0d8SMitch Phillips 
10*f7c5c0d8SMitch Phillips #include <assert.h>
11*f7c5c0d8SMitch Phillips #include <stdlib.h>
12*f7c5c0d8SMitch Phillips #include <string.h>
13*f7c5c0d8SMitch Phillips 
main(int argc,char ** argv)14*f7c5c0d8SMitch Phillips int main(int argc, char **argv) {
15*f7c5c0d8SMitch Phillips   assert(argc == 2);
16*f7c5c0d8SMitch Phillips   if (!strcmp(argv[1], "mallocdel")) {
17*f7c5c0d8SMitch Phillips     int *p = (int *)malloc(16);
18*f7c5c0d8SMitch Phillips     assert(p);
19*f7c5c0d8SMitch Phillips     delete p;
20*f7c5c0d8SMitch Phillips   }
21*f7c5c0d8SMitch Phillips   if (!strcmp(argv[1], "newfree")) {
22*f7c5c0d8SMitch Phillips     int *p = new int;
23*f7c5c0d8SMitch Phillips     assert(p);
24*f7c5c0d8SMitch Phillips     free((void *)p);
25*f7c5c0d8SMitch Phillips   }
26*f7c5c0d8SMitch Phillips   return 0;
27*f7c5c0d8SMitch Phillips }
28*f7c5c0d8SMitch Phillips 
29*f7c5c0d8SMitch Phillips // CHECK-dealloc: ERROR: allocation type mismatch when deallocating address
30*f7c5c0d8SMitch Phillips // CHECK-realloc: ERROR: allocation type mismatch when reallocating address
31