| 1 |
// RUN: %clang_analyze_cc1 \ |
| 2 |
// RUN: -analyzer-checker=core,debug.ExprInspection %s -verify |
| 3 |
|
| 4 |
// These test cases demonstrate lack of Static Analyzer features. |
| 5 |
// The FIXME: tags indicate where we expect different output. |
| 6 |
|
| 7 |
// Handle constructors within new[]. |
| 8 |
|
| 9 |
// When an array of objects is allocated using the operator new[], |
| 10 |
// constructors for all elements of the array are called. |
| 11 |
// We should model (potentially some of) such evaluations, |
| 12 |
// and the same applies for destructors called from operator delete[]. |
| 13 |
|
| 14 |
void clang_analyzer_eval(bool); |
| 15 |
|
| 16 |
struct init_with_list { |
| 17 |
int a; |
| 18 |
init_with_list() : a(1) {} |
| 19 |
}; |
| 20 |
|
| 21 |
struct init_in_body { |
| 22 |
int a; |
| 23 |
init_in_body() { a = 1; } |
| 24 |
}; |
| 25 |
|
| 26 |
struct init_default_member { |
| 27 |
int a = 1; |
| 28 |
}; |
| 29 |
|
| 30 |
void test_automatic() { |
| 31 |
|
| 32 |
init_with_list a1; |
| 33 |
init_in_body a2; |
| 34 |
init_default_member a3; |
| 35 |
|
| 36 |
clang_analyzer_eval(a1.a == 1); // expected-warning {{TRUE}} |
| 37 |
clang_analyzer_eval(a2.a == 1); // expected-warning {{TRUE}} |
| 38 |
clang_analyzer_eval(a3.a == 1); // expected-warning {{TRUE}} |
| 39 |
} |
| 40 |
|
| 41 |
void test_dynamic() { |
| 42 |
|
| 43 |
auto *a1 = new init_with_list; |
| 44 |
auto *a2 = new init_in_body; |
| 45 |
auto *a3 = new init_default_member; |
| 46 |
|
| 47 |
clang_analyzer_eval(a1->a == 1); // expected-warning {{TRUE}} |
| 48 |
clang_analyzer_eval(a2->a == 1); // expected-warning {{TRUE}} |
| 49 |
clang_analyzer_eval(a3->a == 1); // expected-warning {{TRUE}} |
| 50 |
|
| 51 |
delete a1; |
| 52 |
delete a2; |
| 53 |
delete a3; |
| 54 |
} |
| 55 |
|
| 56 |
void test_automatic_aggregate() { |
| 57 |
|
| 58 |
init_with_list a1[1]; |
| 59 |
init_in_body a2[1]; |
| 60 |
init_default_member a3[1]; |
| 61 |
|
| 62 |
clang_analyzer_eval(a1[0].a == 1); // expected-warning {{TRUE}} |
| 63 |
clang_analyzer_eval(a2[0].a == 1); // expected-warning {{TRUE}} |
| 64 |
clang_analyzer_eval(a3[0].a == 1); // expected-warning {{TRUE}} |
| 65 |
} |
| 66 |
|
| 67 |
void test_dynamic_aggregate() { |
| 68 |
|
| 69 |
auto *a1 = new init_with_list[1]; |
| 70 |
auto *a2 = new init_in_body[1]; |
| 71 |
auto *a3 = new init_default_member[1]; |
| 72 |
|
| 73 |
clang_analyzer_eval(a1[0].a == 1); // expected-warning {{TRUE}} |
| 74 |
clang_analyzer_eval(a2[0].a == 1); // expected-warning {{TRUE}} |
| 75 |
clang_analyzer_eval(a3[0].a == 1); // expected-warning {{TRUE}} |
| 76 |
|
| 77 |
delete[] a1; |
| 78 |
delete[] a2; |
| 79 |
delete[] a3; |
| 80 |
} |