blob: 74b1e21a5c97f30b5219d4f8a0e661d4f46604fb [file] [log] [blame]
Artem Dergacheve769fb72018-01-18 00:10:21 +00001// 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 Dergachev13b20262018-01-17 23:46:13 +00002
3void clang_analyzer_eval(bool);
4
5typedef __typeof__(sizeof(int)) size_t;
6
7void *malloc(size_t size);
8
9void *operator new(size_t size) throw() {
Artem Dergacheve769fb72018-01-18 00:10:21 +000010 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 Dergachev13b20262018-01-17 23:46:13 +000013 return nullptr;
14 return x;
15}
16
17void checkNewAndConstructorInlining() {
Artem Dergacheve769fb72018-01-18 00:10:21 +000018 int *s = new int; // expected-note {{Calling 'operator new'}}
19 // expected-note@-1{{Returning from 'operator new'}}
Artem Dergachev13b20262018-01-17 23:46:13 +000020} // expected-warning {{Potential leak of memory pointed to by 's'}}
Artem Dergacheve769fb72018-01-18 00:10:21 +000021 // expected-note@-1 {{Potential leak of memory pointed to by 's'}}