Index: lib/CodeGen/CGExprScalar.cpp
===================================================================
--- lib/CodeGen/CGExprScalar.cpp	(revision 48734)
+++ lib/CodeGen/CGExprScalar.cpp	(working copy)
@@ -19,6 +19,7 @@
 #include "llvm/GlobalVariable.h"
 #include "llvm/Intrinsics.h"
 #include "llvm/Support/Compiler.h"
+#include "llvm/ValueSymbolTable.h"
 #include <cstdarg>
 
 using namespace clang;
@@ -126,6 +127,7 @@
     return EmitLoadOfLValue(E);
   }
   Value *VisitObjCMessageExpr(ObjCMessageExpr *E);
+  Value *VisitObjCIvarRefExpr(ObjCIvarRefExpr *E);
   Value *VisitArraySubscriptExpr(ArraySubscriptExpr *E);
   Value *VisitMemberExpr(Expr *E)           { return EmitLoadOfLValue(E); }
   Value *VisitOCUVectorElementExpr(Expr *E) { return EmitLoadOfLValue(E); }
@@ -449,6 +451,38 @@
   return llvm::UndefValue::get(CGF.ConvertType(E->getType()));
 }
 
+Value *ScalarExprEmitter::VisitObjCIvarRefExpr(ObjCIvarRefExpr *E) {
+  // Objective-C objects are traditionally C structures with their layout
+  // defined at compile-time.  In some implementations, their layout is not
+  // defined until run time in order to allow instance variables to be added to
+  // a class without recompiling all of the subclasses.  If this is the case
+  // then the CGObjCRuntime subclass must return true to LateBoundIvars and
+  // implement the lookup itself.
+  if(CGF.CGM.getObjCRuntime()->LateBoundIVars()) {
+    assert(0 && "FIXME: Implement support for late-bound instance variables");
+    return 0; // Not reached.
+  }
+  else {
+    // Get a structure type for the object
+    QualType ExprTy = E->getBase()->getType();
+    const llvm::Type *ObjectType = ConvertType(ExprTy);
+    //TODO:  Add a special case for isa (index 0)
+    // Work out which index the ivar is
+    ObjCIvarDecl *Decl = E->getDecl();
+    unsigned Index = CGF.CGM.getTypes().getLLVMFieldNo(ExprTy, Decl);
+    
+    // Get object pointer
+    llvm::Value * Object = CGF.EmitLValue(E->getBase()).getAddress();
+    // Coerce object pointer to correct type.
+    if (Object->getType() != ObjectType) {
+      Object = Builder.CreateBitCast(Object, ObjectType);
+    }
+    // Get the correct element
+    llvm::Value * Element = Builder.CreateStructGEP(Object, Index);
+    Element = Builder.CreateLoad(Element, Decl->getName());
+    return Element;
+  }
+}
 Value *ScalarExprEmitter::VisitObjCMessageExpr(ObjCMessageExpr *E) {
   // Only the lookup mechanism and first two arguments of the method
   // implementation vary between runtimes.  We can get the receiver and
@@ -481,11 +515,13 @@
   // Get the selector string
   std::string SelStr = E->getSelector().getName();
   llvm::Constant *Selector = CGF.CGM.GetAddrOfConstantString(SelStr);
-  ConvertType(E->getType());
+
+  llvm::Value *SelPtr = Builder.CreateStructGEP(Selector, 0);
   return Runtime->generateMessageSend(Builder,
       ConvertType(E->getType()),
+      CGF.CurFn->getValueSymbolTable().lookup("self"),
       Receiver,
-      Selector,
+      SelPtr,
       &Args[0],
       Args.size());
 }
Index: lib/CodeGen/CGExpr.cpp
===================================================================
--- lib/CodeGen/CGExpr.cpp	(revision 48734)
+++ lib/CodeGen/CGExpr.cpp	(working copy)
@@ -94,6 +95,9 @@
     return EmitPreDefinedLValue(cast<PreDefinedExpr>(E));
   case Expr::StringLiteralClass:
     return EmitStringLiteralLValue(cast<StringLiteral>(E));
+
+  case Expr::ObjCIvarRefExprClass: 
+    return EmitObjCIvarRefLValue(cast<ObjCIvarRefExpr>(E));
     
   case Expr::UnaryOperatorClass: 
     return EmitUnaryOpLValue(cast<UnaryOperator>(E));
@@ -341,6 +345,17 @@
       return LValue::MakeAddr(CGM.GetAddrOfGlobalVar(VD, false));
     else {
       llvm::Value *V = LocalDeclMap[D];
+      // Check if it's an implicit argument
+      if (!V) {
+        std::string VarName(D->getName());
+        llvm::Function::arg_iterator AI = CurFn->arg_begin();
+        while(AI) {
+          if(VarName == AI->getName()) {
+            return LValue::MakeAddr(AI);
+          }
+        }
+      }
       assert(V && "BlockVarDecl not entered in LocalDeclMap?");
       return LValue::MakeAddr(V);
     }
@@ -555,6 +570,33 @@
   return LValue::MakeAddr(RV.getAggregateAddr());
 }
 
+LValue CodeGenFunction::EmitObjCIvarRefLValue(const ObjCIvarRefExpr *E) {
+  if(CGM.getObjCRuntime()->LateBoundIVars()) {
+    assert(0 && "FIXME: Implement support for late-bound instance variables");
+    return LValue(); // Not reached.
+  }
+  else {
+    // Get a structure type for the object
+    QualType ExprTy = E->getBase()->getType();
+    const llvm::Type *ObjectType = ConvertType(ExprTy);
+    //TODO:  Add a special case for isa (index 0)
+    // Work out which index the ivar is
+    const ObjCIvarDecl *Decl = E->getDecl();
+    unsigned Index = CGM.getTypes().getLLVMFieldNo(ExprTy, Decl);
+    
+    // Get object pointer
+    llvm::Value * Object = EmitLValue(E->getBase()).getAddress();
+    // Coerce object pointer to correct type.
+    if (Object->getType() != ObjectType) {
+      Object = Builder.CreateBitCast(Object, ObjectType);
+    }
+    // Get the correct element
+    llvm::Value * Element = Builder.CreateStructGEP(Object, Index, Decl->getName());
+    return LValue::MakeAddr(Element);
+  }
+}
+
 RValue CodeGenFunction::EmitCallExpr(llvm::Value *Callee, QualType FnType, 
                                      Expr *const *ArgExprs, unsigned NumArgs) {
   // The callee type will always be a pointer to function type, get the function
Index: lib/CodeGen/ModuleBuilder.cpp
===================================================================
--- lib/CodeGen/ModuleBuilder.cpp	(revision 48734)
+++ lib/CodeGen/ModuleBuilder.cpp	(working copy)
@@ -63,6 +63,20 @@
       
       if (FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) {
         Builder->EmitFunction(FD);
+      } else if (ObjCMethodDecl *OMD = dyn_cast<ObjCMethodDecl>(D)){
+        Builder->EmitObjCMethod(OMD);
       } else if (FileVarDecl *FVD = dyn_cast<FileVarDecl>(D)) {
         Builder->EmitGlobalVarDeclarator(FVD);
       } else if (LinkageSpecDecl *LSD = dyn_cast<LinkageSpecDecl>(D)) {
