Dominic Chen | 184c624 | 2017-03-03 18:02:02 +0000 | [diff] [blame] | 1 | // 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 Yartsev | e3377fb | 2013-04-04 23:46:29 +0000 | [diff] [blame] | 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 | //------------------------------------------------------------------ |
| 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 | } |