Artem Dergachev | e769fb7 | 2018-01-18 00:10:21 +0000 | [diff] [blame] | 1 | // RUN: %clang_analyze_cc1 -analyzer-checker=core,debug.ExprInspection,unix.Malloc -analyzer-config c++-allocator-inlining=true -analyzer-output=text -std=c++11 -verify %s |
Artem Dergachev | 13b2026 | 2018-01-17 23:46:13 +0000 | [diff] [blame] | 2 | |
| 3 | void clang_analyzer_eval(bool); |
| 4 | |
| 5 | typedef __typeof__(sizeof(int)) size_t; |
| 6 | |
| 7 | void *malloc(size_t size); |
| 8 | |
| 9 | void *operator new(size_t size) throw() { |
Artem Dergachev | e769fb7 | 2018-01-18 00:10:21 +0000 | [diff] [blame] | 10 | void *x = malloc(size); // expected-note {{Memory is allocated}} |
| 11 | if (!x) // expected-note {{Assuming 'x' is non-null}} |
| 12 | // expected-note@-1 {{Taking false branch}} |
Artem Dergachev | 13b2026 | 2018-01-17 23:46:13 +0000 | [diff] [blame] | 13 | return nullptr; |
| 14 | return x; |
| 15 | } |
| 16 | |
| 17 | void checkNewAndConstructorInlining() { |
Artem Dergachev | e769fb7 | 2018-01-18 00:10:21 +0000 | [diff] [blame] | 18 | int *s = new int; // expected-note {{Calling 'operator new'}} |
| 19 | // expected-note@-1{{Returning from 'operator new'}} |
Artem Dergachev | 13b2026 | 2018-01-17 23:46:13 +0000 | [diff] [blame] | 20 | } // expected-warning {{Potential leak of memory pointed to by 's'}} |
Artem Dergachev | e769fb7 | 2018-01-18 00:10:21 +0000 | [diff] [blame] | 21 | // expected-note@-1 {{Potential leak of memory pointed to by 's'}} |