NewDelete+MismatchedDeallocator_intersections.cpp revision 648cb71625a2ab3164b2cacac9e9cb3d22b03bd7
1// RUN: %clang_cc1 -analyze -analyzer-checker=core,alpha.cplusplus.NewDelete,unix.MismatchedDeallocator -analyzer-store region -std=c++11 -verify %s
2// expected-no-diagnostics
3
4typedef __typeof(sizeof(int)) size_t;
5void *malloc(size_t);
6void free(void *);
7
8//------------------------------------------------------------------
9// Check that alpha.cplusplus.NewDelete + unix.MismatchedDeallocator
10// does not enable warnings produced by the unix.Malloc checker.
11//------------------------------------------------------------------
12void testMallocFreeNoWarn() {
13  int i;
14  free(&i); // no warn
15
16  int *p1 = (int *)malloc(sizeof(int));
17  free(++p1); // no warn
18
19  int *p2 = (int *)malloc(sizeof(int));
20  free(p2);
21  free(p2); // no warn
22
23  int *p3 = (int *)malloc(sizeof(int)); // no warn
24
25  int *p4 = (int *)malloc(sizeof(int));
26  free(p4);
27  int j = *p4; // no warn
28}
29