diff options
author | Manuel Klimek <klimek@google.com> | 2014-07-30 08:34:42 +0000 |
---|---|---|
committer | Manuel Klimek <klimek@google.com> | 2014-07-30 08:34:42 +0000 |
commit | b0042c414e0296b9d3e9cd9b256b63ef28571f1e (patch) | |
tree | aa25c70f1a343f776f0a385c0b95d16a39f11670 /clang/test | |
parent | 3b6c466e961ad97b75a1df79624fe1bc8db02b40 (diff) | |
download | bcm5719-llvm-b0042c414e0296b9d3e9cd9b256b63ef28571f1e.tar.gz bcm5719-llvm-b0042c414e0296b9d3e9cd9b256b63ef28571f1e.zip |
Fix some cases of incorrect handling of lifetime extended temporaries.
MaterializeTemporaryExpr already contains information about the lifetime
of the temporary; if the lifetime is not the full statement, we do not
want to emit a destructor at the end of the full statement for it.
llvm-svn: 214292
Diffstat (limited to 'clang/test')
-rw-r--r-- | clang/test/Analysis/cfg.cpp | 57 |
1 files changed, 56 insertions, 1 deletions
diff --git a/clang/test/Analysis/cfg.cpp b/clang/test/Analysis/cfg.cpp index 65060b16874..28cc440c46f 100644 --- a/clang/test/Analysis/cfg.cpp +++ b/clang/test/Analysis/cfg.cpp @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -analyze -analyzer-checker=debug.DumpCFG -triple x86_64-apple-darwin12 -std=c++11 %s > %t 2>&1 +// RUN: %clang_cc1 -analyze -analyzer-checker=debug.DumpCFG -triple x86_64-apple-darwin12 -analyzer-config cfg-temporary-dtors=true -std=c++11 %s > %t 2>&1 // RUN: FileCheck --input-file=%t %s // CHECK-LABEL: void checkWrap(int i) @@ -377,6 +377,61 @@ void test_placement_new_array() { } +// CHECK-LABEL: void test_lifetime_extended_temporaries() +// CHECK: [B1] +struct LifetimeExtend { LifetimeExtend(int); ~LifetimeExtend(); }; +struct Aggregate { const LifetimeExtend a; const LifetimeExtend b; }; +struct AggregateRef { const LifetimeExtend &a; const LifetimeExtend &b; }; +void test_lifetime_extended_temporaries() { + // CHECK: LifetimeExtend(1); + // CHECK-NEXT: : 1 + // CHECK-NEXT: ~LifetimeExtend() + // CHECK-NOT: ~LifetimeExtend() + { + const LifetimeExtend &l = LifetimeExtend(1); + 1; + } + // CHECK: LifetimeExtend(2) + // CHECK-NEXT: ~LifetimeExtend() + // CHECK-NEXT: : 2 + // CHECK-NOT: ~LifetimeExtend() + { + // No life-time extension. + const int &l = (LifetimeExtend(2), 2); + 2; + } + // CHECK: LifetimeExtend(3) + // CHECK-NEXT: : 3 + // CHECK-NEXT: ~LifetimeExtend() + // CHECK-NOT: ~LifetimeExtend() + { + // The last one is lifetime extended. + const LifetimeExtend &l = (3, LifetimeExtend(3)); + 3; + } + // CHECK: LifetimeExtend(4) + // CHECK-NEXT: ~LifetimeExtend() + // CHECK-NEXT: ~LifetimeExtend() + // CHECK-NEXT: : 4 + // CHECK-NOT: ~LifetimeExtend() + { + Aggregate a{LifetimeExtend(4), LifetimeExtend(4)}; + 4; + } + // CHECK: LifetimeExtend(5) + // CHECK-NEXT: : 5 + // FIXME: We want to emit the destructors of the lifetime + // extended variables here. + // CHECK-NOT: ~LifetimeExtend() + { + AggregateRef a{LifetimeExtend(5), LifetimeExtend(5)}; + 5; + } + // FIXME: Add tests for lifetime extension via subobject + // references (LifetimeExtend().some_member). +} + + // CHECK-LABEL: int *PR18472() // CHECK: [B2 (ENTRY)] // CHECK-NEXT: Succs (1): B1 |