blob: 987ed6a31fa8baa46f7750b2633ec8dec286b7f2 [file] [log] [blame]
Dominic Chen184c6242017-03-03 18:02:02 +00001// RUN: %clang_analyze_cc1 -analyzer-checker=core,cplusplus.NewDelete,unix.MismatchedDeallocator -std=c++11 -verify %s
2// RUN: %clang_analyze_cc1 -analyzer-checker=core,cplusplus.NewDelete,cplusplus.NewDeleteLeaks,unix.MismatchedDeallocator -DLEAKS -std=c++11 -verify %s
Anton Yartseve3377fb2013-04-04 23:46:29 +00003// expected-no-diagnostics
4
5typedef __typeof(sizeof(int)) size_t;
6void *malloc(size_t);
7void free(void *);
8
9//------------------------------------------------------------------
10// Check that alpha.cplusplus.NewDelete + unix.MismatchedDeallocator
11// does not enable warnings produced by the unix.Malloc checker.
12//------------------------------------------------------------------
13void 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}