]> granicus.if.org Git - clang/commitdiff
objc IRGen for Next runtime message API.
authorFariborz Jahanian <fjahanian@apple.com>
Tue, 1 Mar 2011 17:28:13 +0000 (17:28 +0000)
committerFariborz Jahanian <fjahanian@apple.com>
Tue, 1 Mar 2011 17:28:13 +0000 (17:28 +0000)
The prototype for objc_msgSend() is technically variadic -
`id objc_msgSend(id, SEL, ...)`.
But all method calls should use a prototype that matches the method,
not the prototype for objc_msgSend itself().
// rdar://9048030

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@126754 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/CGCall.cpp
lib/CodeGen/CGObjCMac.cpp
test/CodeGenObjC/fpret.m
test/CodeGenObjC/messages.m
test/CodeGenObjC/no-vararg-messaging.m [new file with mode: 0644]

index ae84b6196dfaf802a850327b328b5353c59ef408..1d9a9a6a8ceb00d711b275baf5c8c4276eab589e 100644 (file)
@@ -1275,7 +1275,8 @@ RValue CodeGenFunction::EmitCall(const CGFunctionInfo &CallInfo,
       if (CE->getOpcode() == llvm::Instruction::BitCast &&
           ActualFT->getReturnType() == CurFT->getReturnType() &&
           ActualFT->getNumParams() == CurFT->getNumParams() &&
-          ActualFT->getNumParams() == Args.size()) {
+          ActualFT->getNumParams() == Args.size() &&
+          (CurFT->isVarArg() || !ActualFT->isVarArg())) {
         bool ArgsMatch = true;
         for (unsigned i = 0, e = ActualFT->getNumParams(); i != e; ++i)
           if (ActualFT->getParamType(i) != CurFT->getParamType(i)) {
index 8dbd85f8b738798867ea75602fd4d3d3a147ac97..68fb92081f5d3f4a111ffdeb1a5875834fa13e3c 100644 (file)
@@ -1294,7 +1294,8 @@ private:
                                   llvm::Value *Receiver,
                                   QualType Arg0Ty,
                                   bool IsSuper,
-                                  const CallArgList &CallArgs);
+                                  const CallArgList &CallArgs,
+                                  const ObjCMethodDecl *Method);
 
   /// GetClassGlobal - Return the global variable for the Objective-C
   /// class of the given name.
@@ -5622,7 +5623,8 @@ CodeGen::RValue CGObjCNonFragileABIMac::EmitMessageSend(
   llvm::Value *Receiver,
   QualType Arg0Ty,
   bool IsSuper,
-  const CallArgList &CallArgs) {
+  const CallArgList &CallArgs,
+  const ObjCMethodDecl *Method) {
   // FIXME. Even though IsSuper is passes. This function doese not handle calls
   // to 'super' receivers.
   CodeGenTypes &Types = CGM.getTypes();
@@ -5693,7 +5695,8 @@ CodeGen::RValue CGObjCNonFragileABIMac::EmitMessageSend(
                                                       FunctionType::ExtInfo());
   llvm::Value *Callee = CGF.Builder.CreateStructGEP(Arg1, 0);
   Callee = CGF.Builder.CreateLoad(Callee);
-  const llvm::FunctionType *FTy = Types.GetFunctionType(FnInfo1, true);
+  const llvm::FunctionType *FTy = 
+    Types.GetFunctionType(FnInfo1, Method ? Method->isVariadic() : false);
   Callee = CGF.Builder.CreateBitCast(Callee,
                                      llvm::PointerType::getUnqual(FTy));
   return CGF.EmitCall(FnInfo1, Callee, Return, ActualArgs);
@@ -5716,7 +5719,7 @@ CGObjCNonFragileABIMac::GenerateMessageSend(CodeGen::CodeGenFunction &CGF,
                             false, CallArgs, Method, ObjCTypes)
     : EmitMessageSend(CGF, Return, ResultType, Sel,
                       Receiver, CGF.getContext().getObjCIdType(),
-                      false, CallArgs);
+                      false, CallArgs, Method);
 }
 
 llvm::GlobalVariable *
@@ -5870,7 +5873,7 @@ CGObjCNonFragileABIMac::GenerateMessageSendSuper(CodeGen::CodeGenFunction &CGF,
                             true, CallArgs, Method, ObjCTypes)
     : EmitMessageSend(CGF, Return, ResultType, Sel,
                       ObjCSuper, ObjCTypes.SuperPtrCTy,
-                      true, CallArgs);
+                      true, CallArgs, Method);
 }
 
 llvm::Value *CGObjCNonFragileABIMac::EmitSelector(CGBuilderTy &Builder,
index 48848885c1f6277bc0fe0eabdc150f1d80ecc9a9..bde0caa8ff3a097d98c9753ed540fcdeb0cd7af0 100644 (file)
@@ -16,7 +16,7 @@
 
 // CHECK-X86_32: define void @t0()
 // CHECK-X86_32: call float bitcast {{.*}} @objc_msgSend_fpret to
-// CHECK-X86_32: call double {{.*}} @objc_msgSend_fpret(
+// CHECK-X86_32: call double bitcast {{.*}} @objc_msgSend_fpret to
 // CHECK-X86_32: call x86_fp80 bitcast {{.*}} @objc_msgSend_fpret to
 // CHECK-X86_32: }
 //
index b36fe5b644ed569d9e61eee81f4d674ed9aa5864..449279ca60d26b308137e73c2ede825a8f445be4 100644 (file)
@@ -13,8 +13,8 @@ void f0(id a) {
   int i;
   MyPoint pt = { 1, 2};
 
-  // CHECK-MAC: call {{.*}} @objc_msgSend(
-  // CHECK-MAC-NF: call {{.*}} @objc_msgSend(
+  // CHECK-MAC: call {{.*}} @objc_msgSend to
+  // CHECK-MAC-NF: call {{.*}} @objc_msgSend to
   // CHECK-GNU: call {{.*}} @objc_msg_lookup(
   // CHECK-GNU-NF: call {{.*}} @objc_msg_lookup_sender(
   [a print0];
diff --git a/test/CodeGenObjC/no-vararg-messaging.m b/test/CodeGenObjC/no-vararg-messaging.m
new file mode 100644 (file)
index 0000000..f72820a
--- /dev/null
@@ -0,0 +1,18 @@
+// RUN: %clang_cc1 -triple x86_64-apple-darwin10  -fobjc-nonfragile-abi  -S -o - %s | FileCheck %s
+// rdar://9048030
+
+@interface Foo
++(id)alloc;
+-(id)init;
+-(id)self;
+-(id)retain;
+-(void)release;
+-(id)autorelease;
+@end
+
+void test(void)
+{
+       [[[[[[Foo alloc] init] retain] autorelease] self] release];
+}
+
+// CHECK-NOT: xorb