Generate objc_read_weak for __weak objc loads.

llvm-svn: 59553
This commit is contained in:
Fariborz Jahanian 2008-11-18 21:45:40 +00:00
parent b5e867acff
commit f5125d19e7
5 changed files with 35 additions and 1 deletions

View File

@ -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 =

View File

@ -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);
}

View File

@ -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);

View File

@ -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.

View File

@ -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: