Anton Yartsev | 648cb71 | 2013-04-04 23:46:29 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -analyze -analyzer-checker=core,unix.Malloc,unix.MismatchedDeallocator -analyzer-store region -std=c++11 -verify %s |
| 2 | // expected-no-diagnostics |
| 3 | |
| 4 | typedef __typeof(sizeof(int)) size_t; |
| 5 | void *malloc(size_t); |
| 6 | void free(void *); |
| 7 | |
| 8 | //-------------------------------------------------------------------- |
| 9 | // Check that unix.Malloc + unix.MismatchedDeallocator does not enable |
| 10 | // warnings produced by the alpha.cplusplus.NewDelete checker. |
| 11 | //-------------------------------------------------------------------- |
| 12 | void testNewDeleteNoWarn() { |
| 13 | int i; |
| 14 | delete &i; // no-warning |
| 15 | |
| 16 | int *p1 = new int; |
| 17 | delete ++p1; // no-warning |
| 18 | |
| 19 | int *p2 = new int; |
| 20 | delete p2; |
| 21 | delete p2; // no-warning |
| 22 | |
| 23 | int *p3 = new int; // no-warning |
| 24 | |
| 25 | int *p4 = new int; |
| 26 | delete p4; |
Pirama Arumuga Nainar | 33337ca | 2015-05-06 11:48:57 -0700 | [diff] [blame] | 27 | int j = *p4; // no-warning |
| 28 | } |
| 29 | |
| 30 | void testUseZeroAllocNoWarn() { |
| 31 | int *p1 = (int *)operator new(0); |
| 32 | *p1 = 1; // no-warning |
| 33 | |
| 34 | int *p2 = (int *)operator new[](0); |
| 35 | p2[0] = 1; // no-warning |
| 36 | |
| 37 | int *p3 = new int[0]; |
| 38 | p3[0] = 1; // no-warning |
Anton Yartsev | 648cb71 | 2013-04-04 23:46:29 +0000 | [diff] [blame] | 39 | } |