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