diff options
author | Fariborz Jahanian <fjahanian@apple.com> | 2012-11-27 23:02:53 +0000 |
---|---|---|
committer | Fariborz Jahanian <fjahanian@apple.com> | 2012-11-27 23:02:53 +0000 |
commit | 82c458ea76bf8f0981e3d1b5070c0b0e5878d784 (patch) | |
tree | 1e5970626448a3183b607565ae355fa86956d644 /lib/Sema/SemaExpr.cpp | |
parent | 7aa7eb9d0221bc67e2cd564e703a2427dc212b79 (diff) |
objective-C arc: load of a __weak object happens via call to
objc_loadWeak. This retains and autorelease the weakly-refereced
object. This hidden autorelease sometimes makes __weak variable alive even
after the weak reference is erased, because the object is still referenced
by an autorelease pool. This patch overcomes this behavior by loading a
weak object via call to objc_loadWeakRetained(), followng it by objc_release
at appropriate place, thereby removing the hidden autorelease. // rdar://10849570
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@168740 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Sema/SemaExpr.cpp')
-rw-r--r-- | lib/Sema/SemaExpr.cpp | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/lib/Sema/SemaExpr.cpp b/lib/Sema/SemaExpr.cpp index 840f04f0da..66beb34128 100644 --- a/lib/Sema/SemaExpr.cpp +++ b/lib/Sema/SemaExpr.cpp @@ -504,6 +504,12 @@ ExprResult Sema::DefaultLvalueConversion(Expr *E) { T = T.getUnqualifiedType(); UpdateMarkingForLValueToRValue(E); + + // Loading a __weak object implicitly retains the value, so we need a cleanup to + // balance that. + if (getLangOpts().ObjCAutoRefCount && + E->getType().getObjCLifetime() == Qualifiers::OCL_Weak) + ExprNeedsCleanups = true; ExprResult Res = Owned(ImplicitCastExpr::Create(Context, T, CK_LValueToRValue, E, 0, VK_RValue)); |