aboutsummaryrefslogtreecommitdiff
path: root/lib/CodeGen/CGObjC.cpp
diff options
context:
space:
mode:
authorDouglas Gregor <dgregor@apple.com>2011-06-22 16:12:01 +0000
committerDouglas Gregor <dgregor@apple.com>2011-06-22 16:12:01 +0000
commitd7b23167763f43d3e76b0de26141b1e52613ee3c (patch)
tree71644c427688cfee6c871d4b65502cb81fbe0964 /lib/CodeGen/CGObjC.cpp
parentb4b7b5034bb8304ed03416635bf64c75c39889fc (diff)
When binding a reference to an Automatic Reference Counting temporary,
retain/release the temporary object appropriately. Previously, we would only perform the retain/release operations when the reference would extend the lifetime of the temporary, but this does the wrong thing across calls. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@133620 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/CodeGen/CGObjC.cpp')
-rw-r--r--lib/CodeGen/CGObjC.cpp46
1 files changed, 42 insertions, 4 deletions
diff --git a/lib/CodeGen/CGObjC.cpp b/lib/CodeGen/CGObjC.cpp
index ede2302403..a43f451109 100644
--- a/lib/CodeGen/CGObjC.cpp
+++ b/lib/CodeGen/CGObjC.cpp
@@ -1985,6 +1985,21 @@ namespace {
CallReleaseForObject(QualType type, llvm::Value *addr, bool precise)
: ObjCReleasingCleanup(type, addr), precise(precise) {}
+ using ObjCReleasingCleanup::Emit;
+ static void Emit(CodeGenFunction &CGF, bool IsForEH,
+ QualType type, llvm::Value *addr, bool precise) {
+ // EHScopeStack::Cleanup objects can never have their destructors called,
+ // so use placement new to construct our temporary object.
+ union {
+ void* align;
+ char data[sizeof(CallReleaseForObject)];
+ };
+
+ CallReleaseForObject *Object
+ = new (&align) CallReleaseForObject(type, addr, precise);
+ Object->Emit(CGF, IsForEH);
+ }
+
void release(CodeGenFunction &CGF, QualType type, llvm::Value *addr) {
llvm::Value *ptr = CGF.Builder.CreateLoad(addr, "tmp");
CGF.EmitARCRelease(ptr, precise);
@@ -2033,6 +2048,21 @@ namespace {
CallWeakReleaseForObject(QualType type, llvm::Value *addr)
: ObjCReleasingCleanup(type, addr) {}
+ using ObjCReleasingCleanup::Emit;
+ static void Emit(CodeGenFunction &CGF, bool IsForEH,
+ QualType type, llvm::Value *addr) {
+ // EHScopeStack::Cleanup objects can never have their destructors called,
+ // so use placement new to construct our temporary object.
+ union {
+ void* align;
+ char data[sizeof(CallWeakReleaseForObject)];
+ };
+
+ CallWeakReleaseForObject *Object
+ = new (&align) CallWeakReleaseForObject(type, addr);
+ Object->Emit(CGF, IsForEH);
+ }
+
void release(CodeGenFunction &CGF, QualType type, llvm::Value *addr) {
CGF.EmitARCDestroyWeak(addr);
}
@@ -2099,16 +2129,24 @@ void CodeGenFunction::EmitObjCAutoreleasePoolCleanup(llvm::Value *Ptr) {
void CodeGenFunction::PushARCReleaseCleanup(CleanupKind cleanupKind,
QualType type,
llvm::Value *addr,
- bool precise) {
- EHStack.pushCleanup<CallReleaseForObject>(cleanupKind, type, addr, precise);
+ bool precise,
+ bool forFullExpr) {
+ if (forFullExpr)
+ pushFullExprCleanup<CallReleaseForObject>(cleanupKind, type, addr, precise);
+ else
+ EHStack.pushCleanup<CallReleaseForObject>(cleanupKind, type, addr, precise);
}
/// PushARCWeakReleaseCleanup - Enter a cleanup to perform a weak
/// release on the given object or array of objects.
void CodeGenFunction::PushARCWeakReleaseCleanup(CleanupKind cleanupKind,
QualType type,
- llvm::Value *addr) {
- EHStack.pushCleanup<CallWeakReleaseForObject>(cleanupKind, type, addr);
+ llvm::Value *addr,
+ bool forFullExpr) {
+ if (forFullExpr)
+ pushFullExprCleanup<CallWeakReleaseForObject>(cleanupKind, type, addr);
+ else
+ EHStack.pushCleanup<CallWeakReleaseForObject>(cleanupKind, type, addr);
}
/// PushARCReleaseCleanup - Enter a cleanup to perform a release on a