[cfe-commits] r57898 - in /cfe/trunk: Driver/clang.cpp lib/Sema/Sema.h lib/Sema/SemaDeclObjC.cpp test/SemaObjC/method-lookup-3.m
Steve Naroff
snaroff at apple.com
Tue Oct 21 03:37:53 PDT 2008
Author: snaroff
Date: Tue Oct 21 05:37:50 2008
New Revision: 57898
URL: http://llvm.org/viewvc/llvm-project?rev=57898&view=rev
Log:
Fix <rdar://problem/6261178> clang-on-xcode: [sema] multiple method warning is over enthusiastic.
Fix <rdar://problem/6265257> warnings for ambiguous message send swamp other warnings.
Reworked Sema::MatchTwoMethodDeclarations() to optionally match based on method size and alignment (the default in GCC). Changed Sema::LookupInstanceMethodInGlobalPool() to use this feature.
Added -Wno-struct-selector-match to driver, however didn't hook it up yet. Added a FIXME that says this.
Modified:
cfe/trunk/Driver/clang.cpp
cfe/trunk/lib/Sema/Sema.h
cfe/trunk/lib/Sema/SemaDeclObjC.cpp
cfe/trunk/test/SemaObjC/method-lookup-3.m
Modified: cfe/trunk/Driver/clang.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Driver/clang.cpp?rev=57898&r1=57897&r2=57898&view=diff
==============================================================================
--- cfe/trunk/Driver/clang.cpp (original)
+++ cfe/trunk/Driver/clang.cpp Tue Oct 21 05:37:50 2008
@@ -595,6 +595,11 @@
WarnImplicitFunctionDeclaration("Wimplicit-function-declaration",
llvm::cl::desc("Warn about uses of implicitly defined functions"));
+static llvm::cl::opt<bool>
+WarnNoStrictSelectorMatch("Wno-strict-selector-match",
+ llvm::cl::desc("Do not warn about duplicate methods that have the same size and alignment"),
+ llvm::cl::init(true));
+
/// InitializeDiagnostics - Initialize the diagnostic object, based on the
/// current command line option settings.
static void InitializeDiagnostics(Diagnostic &Diags) {
Modified: cfe/trunk/lib/Sema/Sema.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/Sema.h?rev=57898&r1=57897&r2=57898&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/Sema.h (original)
+++ cfe/trunk/lib/Sema/Sema.h Tue Oct 21 05:37:50 2008
@@ -411,7 +411,8 @@
/// MatchTwoMethodDeclarations - Checks if two methods' type match and returns
/// true, or false, accordingly.
bool MatchTwoMethodDeclarations(const ObjCMethodDecl *Method,
- const ObjCMethodDecl *PrevMethod);
+ const ObjCMethodDecl *PrevMethod,
+ bool matchBasedOnSizeAndAlignment = false);
/// AddInstanceMethodToGlobalPool - All instance methods in a translation
/// unit are added to a global pool. This allows us to efficiently associate
Modified: cfe/trunk/lib/Sema/SemaDeclObjC.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclObjC.cpp?rev=57898&r1=57897&r2=57898&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDeclObjC.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclObjC.cpp Tue Oct 21 05:37:50 2008
@@ -739,16 +739,36 @@
/// returns true, or false, accordingly.
/// TODO: Handle protocol list; such as id<p1,p2> in type comparisons
bool Sema::MatchTwoMethodDeclarations(const ObjCMethodDecl *Method,
- const ObjCMethodDecl *PrevMethod) {
- if (Context.getCanonicalType(Method->getResultType()) !=
- Context.getCanonicalType(PrevMethod->getResultType()))
- return false;
- for (unsigned i = 0, e = Method->getNumParams(); i != e; ++i) {
- ParmVarDecl *ParamDecl = Method->getParamDecl(i);
- ParmVarDecl *PrevParamDecl = PrevMethod->getParamDecl(i);
- if (Context.getCanonicalType(ParamDecl->getType()) !=
- Context.getCanonicalType(PrevParamDecl->getType()))
+ const ObjCMethodDecl *PrevMethod,
+ bool matchBasedOnSizeAndAlignment) {
+ QualType T1 = Context.getCanonicalType(Method->getResultType());
+ QualType T2 = Context.getCanonicalType(PrevMethod->getResultType());
+
+ if (T1 != T2) {
+ // The result types are different.
+ if (!matchBasedOnSizeAndAlignment)
+ return false;
+ // Incomplete types don't have a size and alignment.
+ if (T1->isIncompleteType() || T2->isIncompleteType())
return false;
+ // Check is based on size and alignment.
+ if (Context.getTypeInfo(T1) != Context.getTypeInfo(T2))
+ return false;
+ }
+ for (unsigned i = 0, e = Method->getNumParams(); i != e; ++i) {
+ T1 = Context.getCanonicalType(Method->getParamDecl(i)->getType());
+ T2 = Context.getCanonicalType(PrevMethod->getParamDecl(i)->getType());
+ if (T1 != T2) {
+ // The result types are different.
+ if (!matchBasedOnSizeAndAlignment)
+ return false;
+ // Incomplete types don't have a size and alignment.
+ if (T1->isIncompleteType() || T2->isIncompleteType())
+ return false;
+ // Check is based on size and alignment.
+ if (Context.getTypeInfo(T1) != Context.getTypeInfo(T2))
+ return false;
+ }
}
return true;
}
@@ -776,11 +796,19 @@
}
}
+// FIXME: Finish implementing -Wno-struct-selector-match.
ObjCMethodDecl *Sema::LookupInstanceMethodInGlobalPool(Selector Sel,
SourceRange R) {
ObjCMethodList &MethList = InstanceMethodPool[Sel];
+ bool issueWarning = false;
if (MethList.Method && MethList.Next) {
+ for (ObjCMethodList *Next = MethList.Next; Next; Next = Next->Next)
+ // This checks if the methods differ by size & alignment.
+ if (!MatchTwoMethodDeclarations(MethList.Method, Next->Method, true))
+ issueWarning = true;
+ }
+ if (issueWarning && (MethList.Method && MethList.Next)) {
Diag(R.getBegin(), diag::warn_multiple_method_decl, Sel.getName(), R);
Diag(MethList.Method->getLocStart(), diag::warn_using_decl,
MethList.Method->getSourceRange());
Modified: cfe/trunk/test/SemaObjC/method-lookup-3.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/method-lookup-3.m?rev=57898&r1=57897&r2=57898&view=diff
==============================================================================
--- cfe/trunk/test/SemaObjC/method-lookup-3.m (original)
+++ cfe/trunk/test/SemaObjC/method-lookup-3.m Tue Oct 21 05:37:50 2008
@@ -22,9 +22,9 @@
-(void) x; // expected-warning{{also found}}
-(void) y; // expected-warning{{also found}}
-(void) z; // expected-warning{{also found}}
--(void) setX: (INTERFERE_TYPE) arg; // expected-warning{{also found}}
--(void) setY: (INTERFERE_TYPE) arg; // expected-warning{{also found}}
--(void) setZ: (INTERFERE_TYPE) arg; // expected-warning{{also found}}
+-(void) setX: (INTERFERE_TYPE) arg;
+-(void) setY: (INTERFERE_TYPE) arg;
+-(void) setZ: (INTERFERE_TYPE) arg;
@end
void f0(id a0) {
@@ -40,13 +40,13 @@
}
void f3(id a0, Abstract *a1) {
- [ a0 setX: a1]; // expected-warning {{multiple methods named 'setX:' found}}
+ [ a0 setX: a1];
}
void f4(id a0, Abstract *a1) {
- [ a0 setY: a1]; // expected-warning {{multiple methods named 'setY:' found}}
+ [ a0 setY: a1];
}
void f5(id a0, Abstract *a1) {
- [ a0 setZ: a1]; // expected-warning {{multiple methods named 'setZ:' found}}
+ [ a0 setZ: a1];
}
More information about the cfe-commits
mailing list