diff options
author | Douglas Gregor <dgregor@apple.com> | 2009-11-24 16:43:22 +0000 |
---|---|---|
committer | Douglas Gregor <dgregor@apple.com> | 2009-11-24 16:43:22 +0000 |
commit | 01234bbc1cb94946df8046ad95e17537082b4f71 (patch) | |
tree | eea1a78781609dd8b68cbd5c11160a06fbabc703 /test/CodeGenCXX/condition.cpp | |
parent | 71d9f7c5092772b61d9dd4f8ab7711900012f893 (diff) |
Introduce cleanup scopes for "if" statements in two places:
- Outside the "if", to ensure that we destroy the condition variable
at the end of the "if" statement rather than at the end of the
block containing the "if" statement.
- Inside the "then" and "else" branches, so that we emit then- or
else-local cleanups at the end of the corresponding block when the
block is not a compound statement.
To make adding these new cleanup scopes easier (and since
switch/do/while will all need the same treatment), added the
CleanupScope RAII object to introduce a new cleanup scope and make
sure it gets cleaned up.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@89773 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'test/CodeGenCXX/condition.cpp')
-rw-r--r-- | test/CodeGenCXX/condition.cpp | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/test/CodeGenCXX/condition.cpp b/test/CodeGenCXX/condition.cpp new file mode 100644 index 0000000000..f8a55d8716 --- /dev/null +++ b/test/CodeGenCXX/condition.cpp @@ -0,0 +1,47 @@ +// RUN: clang-cc -triple x86_64-apple-darwin10 -emit-llvm -o - %s | FileCheck %s +void *f(); + +template <typename T> T* g() { + if (T* t = f()) + return t; + + return 0; +} + +void h() { + void *a = g<void>(); +} + +struct X { + X(); + ~X(); + operator bool(); +}; + +struct Y { + Y(); + ~Y(); +}; + +void if_destruct(int z) { + // Verify that the condition variable is destroyed at the end of the + // "if" statement. + // CHECK: call void @_ZN1XC1Ev + // CHECK: call zeroext i1 @_ZN1XcvbEv + if (X x = X()) { + // CHECK: store i32 18 + z = 18; + } + // CHECK: call void @_ZN1XD1Ev + // CHECK: store i32 17 + z = 17; + + // CHECK: call void @_ZN1XC1Ev + if (X x = X()) + Y y; + // CHECK: if.then + // CHECK: call void @_ZN1YC1Ev + // CHECK: call void @_ZN1YD1Ev + // CHECK: if.end + // CHECK: call void @_ZN1XD1Ev +} |