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