diff options
author | Artem Dergachev <artem.dergachev@gmail.com> | 2019-11-07 16:17:39 -0800 |
---|---|---|
committer | Artem Dergachev <artem.dergachev@gmail.com> | 2019-11-07 17:15:53 -0800 |
commit | 5e0fb648420702e47c94de53757928360a106e8c (patch) | |
tree | 0f82d92907ba2d6347d3df21558e10534815ebe3 /clang/test/Analysis/handle_constructors_with_new_array.cpp | |
parent | acac540422e8cee4a77d10f087b2a2b67504b27b (diff) | |
download | bcm5719-llvm-5e0fb648420702e47c94de53757928360a106e8c.tar.gz bcm5719-llvm-5e0fb648420702e47c94de53757928360a106e8c.zip |
[analyzer] Add test cases for the unsupported C++ constructor modeling.
Namely, for the following items:
- Handle constructors within new[];
- Handle constructors for default arguments.
Update the open projects page with a link to the newly added tests
and more hints for potential contributors.
Patch by Daniel Krupp!
Differential Revision: https://reviews.llvm.org/D69308
Diffstat (limited to 'clang/test/Analysis/handle_constructors_with_new_array.cpp')
-rw-r--r-- | clang/test/Analysis/handle_constructors_with_new_array.cpp | 86 |
1 files changed, 86 insertions, 0 deletions
diff --git a/clang/test/Analysis/handle_constructors_with_new_array.cpp b/clang/test/Analysis/handle_constructors_with_new_array.cpp new file mode 100644 index 00000000000..61637afce8d --- /dev/null +++ b/clang/test/Analysis/handle_constructors_with_new_array.cpp @@ -0,0 +1,86 @@ +// RUN: %clang_cc1 -fsyntax-only -analyze \ +// RUN: -analyzer-checker=core,debug.ExprInspection %s -verify + +// These test cases demonstrate lack of Static Analyzer features. +// The FIXME: tags indicate where we expect different output. + +// Handle constructors within new[]. + +// When an array of objects is allocated using the operator new[], +// constructors for all elements of the array are called. +// We should model (potentially some of) such evaluations, +// and the same applies for destructors called from operator delete[]. + +void clang_analyzer_eval(bool); + +struct init_with_list { + int a; + init_with_list() : a(1) {} +}; + +struct init_in_body { + int a; + init_in_body() { a = 1; } +}; + +struct init_default_member { + int a = 1; +}; + +void test_automatic() { + + init_with_list a1; + init_in_body a2; + init_default_member a3; + + clang_analyzer_eval(a1.a == 1); // expected-warning {{TRUE}} + clang_analyzer_eval(a2.a == 1); // expected-warning {{TRUE}} + clang_analyzer_eval(a3.a == 1); // expected-warning {{TRUE}} +} + +void test_dynamic() { + + auto *a1 = new init_with_list; + auto *a2 = new init_in_body; + auto *a3 = new init_default_member; + + clang_analyzer_eval(a1->a == 1); // expected-warning {{TRUE}} + clang_analyzer_eval(a2->a == 1); // expected-warning {{TRUE}} + clang_analyzer_eval(a3->a == 1); // expected-warning {{TRUE}} + + delete a1; + delete a2; + delete a3; +} + +void test_automatic_aggregate() { + + init_with_list a1[1]; + init_in_body a2[1]; + init_default_member a3[1]; + + // FIXME: Should be TRUE, not FALSE. + clang_analyzer_eval(a1[0].a == 1); // expected-warning {{TRUE}} expected-warning {{FALSE}} + // FIXME: Should be TRUE, not FALSE. + clang_analyzer_eval(a2[0].a == 1); // expected-warning {{TRUE}} expected-warning {{FALSE}} + // FIXME: Should be TRUE, not FALSE. + clang_analyzer_eval(a3[0].a == 1); // expected-warning {{TRUE}} expected-warning {{FALSE}} +} + +void test_dynamic_aggregate() { + + auto *a1 = new init_with_list[1]; + auto *a2 = new init_in_body[1]; + auto *a3 = new init_default_member[1]; + + // FIXME: Should be TRUE, not FALSE. + clang_analyzer_eval(a1[0].a == 1); // expected-warning {{TRUE}} expected-warning {{FALSE}} + // FIXME: Should be TRUE, not FALSE. + clang_analyzer_eval(a2[0].a == 1); // expected-warning {{TRUE}} expected-warning {{FALSE}} + // FIXME: Should be TRUE, not FALSE. + clang_analyzer_eval(a3[0].a == 1); // expected-warning {{TRUE}} expected-warning {{FALSE}} + + delete[] a1; + delete[] a2; + delete[] a3; +} |