diff options
author | Fariborz Jahanian <fjahanian@apple.com> | 2010-04-08 21:29:11 +0000 |
---|---|---|
committer | Fariborz Jahanian <fjahanian@apple.com> | 2010-04-08 21:29:11 +0000 |
commit | 7732cc9c0fdc97a2f8cce4e5933d8103213d1aef (patch) | |
tree | 53efdef96efa2f62568200861042d1c1f8c92055 | |
parent | b4c0c2df7a40c753f2eddd8726f807877be4be07 (diff) |
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
-rw-r--r-- | include/clang/AST/DeclObjC.h | 22 | ||||
-rw-r--r-- | lib/AST/ASTContext.cpp | 4 | ||||
-rw-r--r-- | lib/AST/DeclObjC.cpp | 6 | ||||
-rw-r--r-- | lib/Frontend/PCHReaderDecl.cpp | 1 | ||||
-rw-r--r-- | lib/Frontend/PCHWriterDecl.cpp | 1 | ||||
-rw-r--r-- | lib/Sema/SemaDeclObjC.cpp | 1 | ||||
-rw-r--r-- | test/CodeGenObjC/encode-cstyle-method.m | 11 |
7 files changed, 39 insertions, 7 deletions
diff --git a/include/clang/AST/DeclObjC.h b/include/clang/AST/DeclObjC.h index 9b2b6096e8..388e9acb91 100644 --- a/include/clang/AST/DeclObjC.h +++ b/include/clang/AST/DeclObjC.h @@ -136,6 +136,9 @@ private: /// 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 @@ private: 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 @@ public: 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 @@ public: } 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 @@ public: 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 513bbd3871..1fa17f0b4b 100644 --- a/lib/AST/ASTContext.cpp +++ b/lib/AST/ASTContext.cpp @@ -3258,7 +3258,7 @@ void ASTContext::getObjCEncodingForMethodDecl(const ObjCMethodDecl *Decl, // 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 @@ void ASTContext::getObjCEncodingForMethodDecl(const ObjCMethodDecl *Decl, // 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 821e38bdac..db46d89a76 100644 --- a/lib/AST/DeclObjC.cpp +++ b/lib/AST/DeclObjC.cpp @@ -330,11 +330,13 @@ ObjCMethodDecl *ObjCMethodDecl::Create(ASTContext &C, 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 f847becb15..7f80760fbf 100644 --- a/lib/Frontend/PCHReaderDecl.cpp +++ b/lib/Frontend/PCHReaderDecl.cpp @@ -212,6 +212,7 @@ void PCHDeclReader::VisitObjCMethodDecl(ObjCMethodDecl *MD) { 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 42fdb45e22..536c2c6a6f 100644 --- a/lib/Frontend/PCHWriterDecl.cpp +++ b/lib/Frontend/PCHWriterDecl.cpp @@ -211,6 +211,7 @@ void PCHDeclWriter::VisitObjCMethodDecl(ObjCMethodDecl *D) { 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 b422c83162..defda7d5db 100644 --- a/lib/Sema/SemaDeclObjC.cpp +++ b/lib/Sema/SemaDeclObjC.cpp @@ -1588,6 +1588,7 @@ Sema::DeclPtrTy Sema::ActOnMethodDeclaration( } 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 0000000000..187c9bfa9d --- /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 |