Index: clang/lib/CodeGen/CGObjCMac.cpp =================================================================== --- clang/lib/CodeGen/CGObjCMac.cpp +++ clang/lib/CodeGen/CGObjCMac.cpp @@ -876,7 +876,7 @@ /// DirectMethodDefinitions - map of direct methods which have been defined in /// this translation unit. - llvm::DenseMap DirectMethodDefinitions; + llvm::DenseMap DirectMethodDefinitions; /// PropertyNames - uniqued method variable names. llvm::DenseMap PropertyNames; @@ -4027,20 +4027,20 @@ llvm::Function * CGObjCCommonMac::GenerateDirectMethod(const ObjCMethodDecl *OMD, const ObjCContainerDecl *CD) { - auto I = DirectMethodDefinitions.find(OMD); - if (I != DirectMethodDefinitions.end()) - return I->second; - SmallString<256> Name; GetNameForMethod(OMD, CD, Name); + auto I = DirectMethodDefinitions.find(Name); + if (I != DirectMethodDefinitions.end()) + return I->second; + CodeGenTypes &Types = CGM.getTypes(); llvm::FunctionType *MethodTy = Types.GetFunctionType(Types.arrangeObjCMethodDeclaration(OMD)); llvm::Function *Method = llvm::Function::Create(MethodTy, llvm::GlobalValue::ExternalLinkage, Name.str(), &CGM.getModule()); - DirectMethodDefinitions.insert(std::make_pair(OMD, Method)); + DirectMethodDefinitions.insert(std::make_pair(Method->getName(), Method)); return Method; } Index: clang/lib/Sema/SemaDeclObjC.cpp =================================================================== --- clang/lib/Sema/SemaDeclObjC.cpp +++ clang/lib/Sema/SemaDeclObjC.cpp @@ -4836,6 +4836,8 @@ cast(ClassDecl)->addDecl(ObjCMethod); } + ObjCMethod->createImplicitParams(Context, ObjCMethod->getClassInterface()); + if (PrevMethod) { // You can never have two method definitions with the same name. Diag(ObjCMethod->getLocation(), diag::err_duplicate_method_decl) Index: clang/test/CodeGenObjC/direct-method.m =================================================================== --- clang/test/CodeGenObjC/direct-method.m +++ clang/test/CodeGenObjC/direct-method.m @@ -11,6 +11,7 @@ __attribute__((objc_root_class)) @interface Root +- (int)getInt __attribute__((objc_direct)); @end @implementation Root @@ -173,3 +174,9 @@ // CHECK-LABEL: define hidden void @"\01-[Foo setGetDynamic_setDirect:]"( // CHECK-LABEL: define internal void @"\01-[Foo .cxx_destruct]"( @end + +int useRoot(Root *r) { + // CHEC-LABEL: define i32 @useRoot + // CHECK: %call = call i32 bitcast {{.*}} @"\01-[Root getInt]" + return [r getInt]; +}