diff options
| author | Artem Dergachev <artem.dergachev@gmail.com> | 2018-03-12 23:36:12 +0000 |
|---|---|---|
| committer | Artem Dergachev <artem.dergachev@gmail.com> | 2018-03-12 23:36:12 +0000 |
| commit | 09a7c0c77de0e48e819b8b07ee06095396e108f0 (patch) | |
| tree | 5d2f66c569af4e8a109f95d9e012f2618a062ae6 /clang/test/Analysis | |
| parent | 98a24bf76d08f2cd69c0205e0313cbcddcc658cb (diff) | |
| download | bcm5719-llvm-09a7c0c77de0e48e819b8b07ee06095396e108f0.tar.gz bcm5719-llvm-09a7c0c77de0e48e819b8b07ee06095396e108f0.zip | |
[analyzer] Support temporaries conjured by conservatively evaluated functions.
Properly perform destruction and lifetime extension of such temporaries.
C++ object-type return values of conservatively evaluated functions are now
represented as compound values of well-defined temporary object regions. The
function creates a region that represents the temporary object and will later
be used for destruction or materialization, invalidates it, and returns the
invalidated compound value of the object.
Differential Revision: https://reviews.llvm.org/D44131
llvm-svn: 327348
Diffstat (limited to 'clang/test/Analysis')
| -rw-r--r-- | clang/test/Analysis/explain-svals.cpp | 2 | ||||
| -rw-r--r-- | clang/test/Analysis/temporaries.cpp | 52 |
2 files changed, 51 insertions, 3 deletions
diff --git a/clang/test/Analysis/explain-svals.cpp b/clang/test/Analysis/explain-svals.cpp index d4b56a34825..ecb5af1f8ef 100644 --- a/clang/test/Analysis/explain-svals.cpp +++ b/clang/test/Analysis/explain-svals.cpp @@ -94,5 +94,5 @@ public: void test_6() { clang_analyzer_explain(conjure_S()); // expected-warning-re{{{{^lazily frozen compound value of temporary object constructed at statement 'conjure_S\(\)'$}}}} - clang_analyzer_explain(conjure_S().z); // expected-warning-re{{{{^value derived from \(symbol of type 'struct S' conjured at statement 'conjure_S\(\)'\) for field 'z' of temporary object constructed at statement 'conjure_S\(\)'$}}}} + clang_analyzer_explain(conjure_S().z); // expected-warning-re{{{{^value derived from \(symbol of type 'int' conjured at statement 'conjure_S\(\)'\) for field 'z' of temporary object constructed at statement 'conjure_S\(\)'$}}}} } diff --git a/clang/test/Analysis/temporaries.cpp b/clang/test/Analysis/temporaries.cpp index 681ccc957e0..0d2c610d6b8 100644 --- a/clang/test/Analysis/temporaries.cpp +++ b/clang/test/Analysis/temporaries.cpp @@ -895,6 +895,45 @@ void test_ternary_temporary_with_copy(int coin) { } } // namespace test_match_constructors_and_destructors +namespace destructors_for_return_values { + +class C { +public: + ~C() { + 1 / 0; // expected-warning{{Division by zero}} + } +}; + +C make(); + +void testFloatingCall() { + make(); + // Should have divided by zero in the destructor. + clang_analyzer_warnIfReached(); +#ifndef TEMPORARY_DTORS + // expected-warning@-2{{REACHABLE}} +#endif +} + +void testLifetimeExtendedCall() { + { + const C &c = make(); + clang_analyzer_warnIfReached(); // expected-warning{{REACHABLE}} + } + // Should have divided by zero in the destructor. + clang_analyzer_warnIfReached(); // no-warning +} + +void testCopiedCall() { + C c = make(); + // Should have divided by zero in the temporary destructor. + clang_analyzer_warnIfReached(); +#ifndef TEMPORARY_DTORS + // expected-warning@-2{{REACHABLE}} +#endif +} +} // namespace destructors_for_return_values + namespace dont_forget_destructor_around_logical_op { int glob; @@ -922,8 +961,17 @@ void test(int coin) { // return value of get() was initialized. However, we didn't track // temporaries returned from functions, so we took the wrong branch. coin && is(get()); // no-crash - // FIXME: Should be true once we inline all destructors. - clang_analyzer_eval(glob); // expected-warning{{UNKNOWN}} + if (coin) { + clang_analyzer_eval(glob); +#ifdef TEMPORARY_DTORS + // expected-warning@-2{{TRUE}} +#else + // expected-warning@-4{{UNKNOWN}} +#endif + } else { + // The destructor is not called on this branch. + clang_analyzer_eval(glob); // expected-warning{{UNKNOWN}} + } } } // namespace dont_forget_destructor_around_logical_op |

