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
diff --git a/lib/CodeGen/CodeGenFunction.cpp b/lib/CodeGen/CodeGenFunction.cpp
index c804098..a07eaff 100644
--- a/lib/CodeGen/CodeGenFunction.cpp
+++ b/lib/CodeGen/CodeGenFunction.cpp
@@ -97,7 +97,13 @@
// 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 @@
assert(!verifyFunction(*CurFn) && "Generated method is not well formed.");
}
+llvm::Value *CodeGenFunction::LoadObjCSelf(void)
+{
+ if(const ObjCMethodDecl *OMD = dyn_cast<ObjCMethodDecl>(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<unsigned>(
getContext().getTypeSize(getContext().getPointerType(getContext().VoidTy)));
CurFuncDecl = FD;
- FnRetTy = CurFuncDecl->getType()->getAsFunctionType()->getResultType();
+ FnRetTy = FD->getType()->getAsFunctionType()->getResultType();
CurFn = cast<llvm::Function>(CGM.GetAddrOfFunctionDecl(FD, true));