From c8aa5f1f264fb230c38182adab944232bb160c2b Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Fri, 4 Apr 2008 04:07:35 +0000 Subject: Codegen assignment to self correctly, patch by David Chisnall! git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@49201 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/CodeGen/CodeGenFunction.cpp | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) (limited to 'lib/CodeGen/CodeGenFunction.cpp') diff --git a/lib/CodeGen/CodeGenFunction.cpp b/lib/CodeGen/CodeGenFunction.cpp index c804098ec9..a07eaff305 100644 --- a/lib/CodeGen/CodeGenFunction.cpp +++ b/lib/CodeGen/CodeGenFunction.cpp @@ -97,7 +97,13 @@ void CodeGenFunction::GenerateObjCMethod(const ObjCMethodDecl *OMD) { // TODO: Add something to AST to let the runtime specify the names and types // of these. llvm::Value *&DMEntry = LocalDeclMap[&(*OMD->getSelfDecl())]; - DMEntry = AI; + const llvm::Type *SelfTy = AI->getType(); + llvm::Value *DeclPtr = new llvm::AllocaInst(SelfTy, 0, "self.addr", + AllocaInsertPt); + + // Store the initial value into the alloca. + Builder.CreateStore(AI, DeclPtr); + DMEntry = DeclPtr; ++AI; ++AI; @@ -130,13 +136,22 @@ void CodeGenFunction::GenerateObjCMethod(const ObjCMethodDecl *OMD) { assert(!verifyFunction(*CurFn) && "Generated method is not well formed."); } +llvm::Value *CodeGenFunction::LoadObjCSelf(void) +{ + if(const ObjCMethodDecl *OMD = dyn_cast(CurFuncDecl)) { + llvm::Value *SelfPtr = LocalDeclMap[&(*OMD->getSelfDecl())]; + return Builder.CreateLoad(SelfPtr, "self"); + } + return NULL; +} + void CodeGenFunction::GenerateCode(const FunctionDecl *FD) { LLVMIntTy = ConvertType(getContext().IntTy); LLVMPointerWidth = static_cast( getContext().getTypeSize(getContext().getPointerType(getContext().VoidTy))); CurFuncDecl = FD; - FnRetTy = CurFuncDecl->getType()->getAsFunctionType()->getResultType(); + FnRetTy = FD->getType()->getAsFunctionType()->getResultType(); CurFn = cast(CGM.GetAddrOfFunctionDecl(FD, true)); -- cgit v1.2.3-18-g5258