Implement method type encoding in the presense
of c-style arguments. Completes radar 7445205.



git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@100813 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/include/clang/AST/DeclObjC.h b/include/clang/AST/DeclObjC.h
index 9b2b609..388e9ac 100644
--- a/include/clang/AST/DeclObjC.h
+++ b/include/clang/AST/DeclObjC.h
@@ -136,6 +136,9 @@
   /// in, inout, etc.
   unsigned objcDeclQualifier : 6;
 
+  // Number of args separated by ':' in a method declaration.
+  unsigned NumSelectorArgs;
+
   // Result type of this method.
   QualType MethodDeclType;
   
@@ -167,13 +170,15 @@
                  bool isInstance = true,
                  bool isVariadic = false,
                  bool isSynthesized = false,
-                 ImplementationControl impControl = None)
+                 ImplementationControl impControl = None,
+                 unsigned numSelectorArgs = 0)
   : NamedDecl(ObjCMethod, contextDecl, beginLoc, SelInfo),
     DeclContext(ObjCMethod),
     IsInstance(isInstance), IsVariadic(isVariadic),
     IsSynthesized(isSynthesized),
     DeclImplementation(impControl), objcDeclQualifier(OBJC_TQ_None),
-    MethodDeclType(T), ResultTInfo(ResultTInfo),
+    NumSelectorArgs(numSelectorArgs), MethodDeclType(T), 
+    ResultTInfo(ResultTInfo),
     EndLoc(endLoc), Body(0), SelfDecl(0), CmdDecl(0) {}
 
   virtual ~ObjCMethodDecl() {}
@@ -197,7 +202,8 @@
                                 bool isInstance = true,
                                 bool isVariadic = false,
                                 bool isSynthesized = false,
-                                ImplementationControl impControl = None);
+                                ImplementationControl impControl = None,
+                                unsigned numSelectorArgs = 0);
 
   virtual ObjCMethodDecl *getCanonicalDecl();
   const ObjCMethodDecl *getCanonicalDecl() const {
@@ -209,6 +215,11 @@
   }
   void setObjCDeclQualifier(ObjCDeclQualifier QV) { objcDeclQualifier = QV; }
 
+  unsigned getNumSelectorArgs() const { return NumSelectorArgs; }
+  void setNumSelectorArgs(unsigned numSelectorArgs) { 
+    NumSelectorArgs = numSelectorArgs; 
+  }
+  
   // Location information, modeled after the Stmt API.
   SourceLocation getLocStart() const { return getLocation(); }
   SourceLocation getLocEnd() const { return EndLoc; }
@@ -235,6 +246,11 @@
   typedef ObjCList<ParmVarDecl>::iterator param_iterator;
   param_iterator param_begin() const { return ParamInfo.begin(); }
   param_iterator param_end() const { return ParamInfo.end(); }
+  // This method returns and of the parameters which are part of the selector
+  // name mangling requirements.
+  param_iterator sel_param_end() const { 
+    return ParamInfo.begin() + NumSelectorArgs; 
+  }
 
   void setMethodParams(ASTContext &C, ParmVarDecl *const *List, unsigned Num) {
     ParamInfo.set(List, Num, C);
diff --git a/lib/AST/ASTContext.cpp b/lib/AST/ASTContext.cpp
index 513bbd3..1fa17f0 100644
--- a/lib/AST/ASTContext.cpp
+++ b/lib/AST/ASTContext.cpp
@@ -3258,7 +3258,7 @@
   // their size.
   CharUnits ParmOffset = 2 * PtrSize;
   for (ObjCMethodDecl::param_iterator PI = Decl->param_begin(),
-       E = Decl->param_end(); PI != E; ++PI) {
+       E = Decl->sel_param_end(); PI != E; ++PI) {
     QualType PType = (*PI)->getType();
     CharUnits sz = getObjCEncodingTypeSize(PType);
     assert (sz.isPositive() && 
@@ -3272,7 +3272,7 @@
   // Argument types.
   ParmOffset = 2 * PtrSize;
   for (ObjCMethodDecl::param_iterator PI = Decl->param_begin(),
-       E = Decl->param_end(); PI != E; ++PI) {
+       E = Decl->sel_param_end(); PI != E; ++PI) {
     ParmVarDecl *PVDecl = *PI;
     QualType PType = PVDecl->getOriginalType();
     if (const ArrayType *AT =
diff --git a/lib/AST/DeclObjC.cpp b/lib/AST/DeclObjC.cpp
index 821e38b..db46d89 100644
--- a/lib/AST/DeclObjC.cpp
+++ b/lib/AST/DeclObjC.cpp
@@ -330,11 +330,13 @@
                                        bool isInstance,
                                        bool isVariadic,
                                        bool isSynthesized,
-                                       ImplementationControl impControl) {
+                                       ImplementationControl impControl,
+                                       unsigned numSelectorArgs) {
   return new (C) ObjCMethodDecl(beginLoc, endLoc,
                                 SelInfo, T, ResultTInfo, contextDecl,
                                 isInstance,
-                                isVariadic, isSynthesized, impControl);
+                                isVariadic, isSynthesized, impControl,
+                                numSelectorArgs);
 }
 
 void ObjCMethodDecl::Destroy(ASTContext &C) {
diff --git a/lib/Frontend/PCHReaderDecl.cpp b/lib/Frontend/PCHReaderDecl.cpp
index f847bec..7f80760 100644
--- a/lib/Frontend/PCHReaderDecl.cpp
+++ b/lib/Frontend/PCHReaderDecl.cpp
@@ -212,6 +212,7 @@
   MD->setSynthesized(Record[Idx++]);
   MD->setDeclImplementation((ObjCMethodDecl::ImplementationControl)Record[Idx++]);
   MD->setObjCDeclQualifier((Decl::ObjCDeclQualifier)Record[Idx++]);
+  MD->setNumSelectorArgs(unsigned(Record[Idx++]));
   MD->setResultType(Reader.GetType(Record[Idx++]));
   MD->setResultTypeSourceInfo(Reader.GetTypeSourceInfo(Record, Idx));
   MD->setEndLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
diff --git a/lib/Frontend/PCHWriterDecl.cpp b/lib/Frontend/PCHWriterDecl.cpp
index 42fdb45..536c2c6 100644
--- a/lib/Frontend/PCHWriterDecl.cpp
+++ b/lib/Frontend/PCHWriterDecl.cpp
@@ -211,6 +211,7 @@
   Record.push_back(D->getImplementationControl());
   // FIXME: stable encoding for in/out/inout/bycopy/byref/oneway
   Record.push_back(D->getObjCDeclQualifier());
+  Record.push_back(D->getNumSelectorArgs());
   Writer.AddTypeRef(D->getResultType(), Record);
   Writer.AddTypeSourceInfo(D->getResultTypeSourceInfo(), Record);
   Writer.AddSourceLocation(D->getLocEnd(), Record);
diff --git a/lib/Sema/SemaDeclObjC.cpp b/lib/Sema/SemaDeclObjC.cpp
index b422c83..defda7d 100644
--- a/lib/Sema/SemaDeclObjC.cpp
+++ b/lib/Sema/SemaDeclObjC.cpp
@@ -1588,6 +1588,7 @@
   }
   
   ObjCMethod->setMethodParams(Context, Params.data(), Params.size());
+  ObjCMethod->setNumSelectorArgs(Sel.getNumArgs());
   ObjCMethod->setObjCDeclQualifier(
     CvtQTToAstBitMask(ReturnQT.getObjCDeclQualifier()));
   const ObjCMethodDecl *PrevMethod = 0;
diff --git a/test/CodeGenObjC/encode-cstyle-method.m b/test/CodeGenObjC/encode-cstyle-method.m
new file mode 100644
index 0000000..187c9bf
--- /dev/null
+++ b/test/CodeGenObjC/encode-cstyle-method.m
@@ -0,0 +1,11 @@
+// RUN: %clang_cc1 -triple x86_64-apple-darwin10  -emit-llvm -o - %s | FileCheck -check-prefix LP64 %s
+// rdar: // 7445205
+
+@interface Foo 
+- (id)test:(id)one, id two;
+@end
+
+@implementation Foo
+- (id)test:(id )one, id two {return two; } @end
+
+// CHECK-LP64: internal global [11 x i8] c"@24@0:8@16