blob: 3cf5b0f8cc9fcd88bd28fac445f9564335df583a [file] [log] [blame]
Jordan Rosee38c1c22012-06-20 01:32:01 +00001// RUN: %clang_cc1 -analyze -analyzer-checker=core,unix.Malloc,debug.ExprInspection -analyzer-store region -verify %s
Zhongxing Xu40ab43b2010-04-20 05:48:57 +00002
Jordan Rosee38c1c22012-06-20 01:32:01 +00003void clang_analyzer_eval(bool);
4
5typedef typeof(sizeof(int)) size_t;
6extern "C" void *malloc(size_t);
7
8// This is the standard placement new.
9inline void* operator new(size_t, void* __p) throw()
10{
11 return __p;
Zhongxing Xu48fb3222010-04-21 02:22:25 +000012}
Zhongxing Xu40ab43b2010-04-20 05:48:57 +000013
Jordan Rosee38c1c22012-06-20 01:32:01 +000014void *testPlacementNew() {
15 int *x = (int *)malloc(sizeof(int));
16 *x = 1;
17 clang_analyzer_eval(*x == 1); // expected-warning{{TRUE}};
18
19 void *y = new (x) int;
20 clang_analyzer_eval(x == y); // expected-warning{{TRUE}};
21 clang_analyzer_eval(*x == 1); // expected-warning{{UNKNOWN}};
22
23 return y;
24}
25
26void *operator new(size_t, size_t, int *);
27void *testCustomNew() {
28 int x[1] = {1};
29 clang_analyzer_eval(*x == 1); // expected-warning{{TRUE}};
30
31 void *y = new (0, x) int;
32 clang_analyzer_eval(*x == 1); // expected-warning{{UNKNOWN}};
33
34 return y; // no-warning
Zhongxing Xu40ab43b2010-04-20 05:48:57 +000035}
36