diff options
author | Fariborz Jahanian <fjahanian@apple.com> | 2009-08-04 01:07:16 +0000 |
---|---|---|
committer | Fariborz Jahanian <fjahanian@apple.com> | 2009-08-04 01:07:16 +0000 |
commit | dbdec8bcb5686cd34763db49488f77e88c43eb64 (patch) | |
tree | 3a851e2cd1bd7315b04ab517f689c3ebe9a606f0 /lib/Sema/SemaDeclObjC.cpp | |
parent | 8eec7c00e6e8e7243776d89c3897a48d354aecbf (diff) |
Compare matching selectors in current and
super class(s) and warn on any parameter
type mismatch if potentially unsafe.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@78029 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Sema/SemaDeclObjC.cpp')
-rw-r--r-- | lib/Sema/SemaDeclObjC.cpp | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/lib/Sema/SemaDeclObjC.cpp b/lib/Sema/SemaDeclObjC.cpp index 26f590578c..0ee0ad730f 100644 --- a/lib/Sema/SemaDeclObjC.cpp +++ b/lib/Sema/SemaDeclObjC.cpp @@ -1464,6 +1464,37 @@ void Sema::ProcessPropertyDecl(ObjCPropertyDecl *property, AddInstanceMethodToGlobalPool(SetterMethod); } +void Sema::CompareMethodParamsInBaseAndSuper(Decl *ClassDecl, + ObjCMethodDecl *Method, + bool IsInstance) { + if (ObjCInterfaceDecl *ID = dyn_cast<ObjCInterfaceDecl>(ClassDecl)) + while (ObjCInterfaceDecl *SD = ID->getSuperClass()) { + if (ObjCMethodDecl *SuperMethodDecl = + SD->lookupMethod(Method->getSelector(), IsInstance)) { + ObjCMethodDecl::param_iterator ParamI = Method->param_begin(), + E = Method->param_end(); + ObjCMethodDecl::param_iterator PrevI = + SuperMethodDecl->param_begin(); + for (; ParamI != E; ++ParamI, ++PrevI) { + assert(PrevI != SuperMethodDecl->param_end() && "Param mismatch"); + QualType T1 = Context.getCanonicalType((*ParamI)->getType()); + QualType T2 = Context.getCanonicalType((*PrevI)->getType()); + if (T1 != T2) { + AssignConvertType ConvTy = CheckAssignmentConstraints(T1, T2); + if (ConvTy == Incompatible || ConvTy == IncompatiblePointer) { + Diag((*ParamI)->getLocation(), diag::ext_typecheck_base_super) + << T1 << T2; + Diag(SuperMethodDecl->getLocation(), + diag::note_previous_declaration); + return; + } + } + } + } + ID = SD; + } +} + // Note: For class/category implemenations, allMethods/allProperties is // always null. void Sema::ActOnAtEnd(SourceLocation AtEndLoc, DeclPtrTy classDecl, @@ -1509,6 +1540,7 @@ void Sema::ActOnAtEnd(SourceLocation AtEndLoc, DeclPtrTy classDecl, InsMap[Method->getSelector()] = Method; /// The following allows us to typecheck messages to "id". AddInstanceMethodToGlobalPool(Method); + CompareMethodParamsInBaseAndSuper(ClassDecl, Method, true); } } else { @@ -1526,6 +1558,7 @@ void Sema::ActOnAtEnd(SourceLocation AtEndLoc, DeclPtrTy classDecl, ClsMap[Method->getSelector()] = Method; /// The following allows us to typecheck messages to "Class". AddFactoryMethodToGlobalPool(Method); + CompareMethodParamsInBaseAndSuper(ClassDecl, Method, false); } } } |