diff options
author | Fariborz Jahanian <fjahanian@apple.com> | 2008-11-18 21:45:40 +0000 |
---|---|---|
committer | Fariborz Jahanian <fjahanian@apple.com> | 2008-11-18 21:45:40 +0000 |
commit | 6dc2317b59cb1180a59f6c283d96b7a5dfeb5307 (patch) | |
tree | 284b0854afd1d6f568597dc0ce725ac5737df6bb | |
parent | 6d657c4809d9128be88705d32768de007b988212 (diff) |
Generate objc_read_weak for __weak objc loads.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@59553 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | lib/CodeGen/CGExpr.cpp | 8 | ||||
-rw-r--r-- | lib/CodeGen/CGObjCGNU.cpp | 8 | ||||
-rw-r--r-- | lib/CodeGen/CGObjCMac.cpp | 14 | ||||
-rw-r--r-- | lib/CodeGen/CGObjCRuntime.h | 2 | ||||
-rw-r--r-- | lib/CodeGen/CGValue.h | 4 |
5 files changed, 35 insertions, 1 deletions
diff --git a/lib/CodeGen/CGExpr.cpp b/lib/CodeGen/CGExpr.cpp index 993562592b..d537c9ca81 100644 --- a/lib/CodeGen/CGExpr.cpp +++ b/lib/CodeGen/CGExpr.cpp @@ -151,6 +151,14 @@ LValue CodeGenFunction::EmitLValue(const Expr *E) { /// this method emits the address of the lvalue, then loads the result as an /// rvalue, returning the rvalue. RValue CodeGenFunction::EmitLoadOfLValue(LValue LV, QualType ExprType) { + if (LV.isObjcWeak()) { + // load of a __weak object. + llvm::Value *AddrWeakObj = LV.getAddress(); + llvm::Value *read_weak = CGM.getObjCRuntime().EmitObjCWeakCall(*this, + AddrWeakObj); + return RValue::get(read_weak); + } + if (LV.isSimple()) { llvm::Value *Ptr = LV.getAddress(); const llvm::Type *EltTy = diff --git a/lib/CodeGen/CGObjCGNU.cpp b/lib/CodeGen/CGObjCGNU.cpp index 0833b0832d..d57710c5e5 100644 --- a/lib/CodeGen/CGObjCGNU.cpp +++ b/lib/CodeGen/CGObjCGNU.cpp @@ -130,6 +130,8 @@ public: const ObjCAtThrowStmt &S); virtual void EmitSynchronizedStmt(CodeGen::CodeGenFunction &CGF, const ObjCAtSynchronizedStmt &S); + virtual llvm::Value * EmitObjCWeakCall(CodeGen::CodeGenFunction &CGF, + llvm::Value *AddrWeakObj); }; } // end anonymous namespace @@ -968,6 +970,12 @@ void CGObjCGNU::EmitSynchronizedStmt(CodeGen::CodeGenFunction &CGF, CGF.ErrorUnsupported(&S, "@synchronized statement"); } +llvm::Value * CGObjCGNU::EmitObjCWeakCall(CodeGen::CodeGenFunction &CGF, + llvm::Value *AddrWeakObj) +{ + return 0; +} + CodeGen::CGObjCRuntime *CodeGen::CreateGNUObjCRuntime(CodeGen::CodeGenModule &CGM){ return new CGObjCGNU(CGM); } diff --git a/lib/CodeGen/CGObjCMac.cpp b/lib/CodeGen/CGObjCMac.cpp index 1591831458..f3cf21eb31 100644 --- a/lib/CodeGen/CGObjCMac.cpp +++ b/lib/CodeGen/CGObjCMac.cpp @@ -454,7 +454,8 @@ public: const ObjCAtThrowStmt &S); virtual void EmitSynchronizedStmt(CodeGen::CodeGenFunction &CGF, const ObjCAtSynchronizedStmt &S); - + virtual llvm::Value * EmitObjCWeakCall(CodeGen::CodeGenFunction &CGF, + llvm::Value *AddrWeakObj); }; } // end anonymous namespace @@ -1775,6 +1776,17 @@ void CodeGenFunction::EmitJumpThroughFinally(ObjCEHEntry *E, EmitBranch(ExecuteTryExit ? E->FinallyBlock : E->FinallyNoExit); } +/// EmitObjCWeakCall - Code gen for loading value of a __weak +/// object: objc_read_weak (id *src) +/// +llvm::Value * CGObjCMac::EmitObjCWeakCall(CodeGen::CodeGenFunction &CGF, + llvm::Value *AddrWeakObj) +{ + llvm::Value *read_weak = CGF.Builder.CreateCall(ObjCTypes.GcReadWeakFn, + AddrWeakObj, "weakobj"); + return read_weak; +} + /// EmitSynchronizedStmt - Code gen for @synchronized(expr) stmt; /// Effectively generating code for: /// objc_sync_enter(expr); diff --git a/lib/CodeGen/CGObjCRuntime.h b/lib/CodeGen/CGObjCRuntime.h index 435e1483e3..37544e47e1 100644 --- a/lib/CodeGen/CGObjCRuntime.h +++ b/lib/CodeGen/CGObjCRuntime.h @@ -145,6 +145,8 @@ public: const ObjCAtThrowStmt &S) = 0; virtual void EmitSynchronizedStmt(CodeGen::CodeGenFunction &CGF, const ObjCAtSynchronizedStmt &S) = 0; + virtual llvm::Value * EmitObjCWeakCall(CodeGen::CodeGenFunction &CGF, + llvm::Value *AddrWeakObj) = 0; }; /// Creates an instance of an Objective-C runtime class. diff --git a/lib/CodeGen/CGValue.h b/lib/CodeGen/CGValue.h index 505381eb41..ef2cb033c9 100644 --- a/lib/CodeGen/CGValue.h +++ b/lib/CodeGen/CGValue.h @@ -138,6 +138,10 @@ private: static void SetQualifiers(unsigned Qualifiers, LValue& R) { R.Volatile = (Qualifiers&QualType::Volatile)!=0; R.Restrict = (Qualifiers&QualType::Restrict)!=0; + // FIXME: Convenient place to set objc flags to 0. This + // should really be done in a user-defined constructor instead. + R.ObjcWeak = 0; + R.ObjcStrong = 0; } public: |