r197534 - Objctive-C. warn if dealloc is being overridden in
Fariborz Jahanian
fjahanian at apple.com
Tue Dec 17 14:44:28 PST 2013
Author: fjahanian
Date: Tue Dec 17 16:44:28 2013
New Revision: 197534
URL: http://llvm.org/viewvc/llvm-project?rev=197534&view=rev
Log:
Objctive-C. warn if dealloc is being overridden in
a category implementation. // rdar://15397430
Modified:
cfe/trunk/include/clang/Basic/DiagnosticGroups.td
cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
cfe/trunk/lib/Sema/SemaDeclObjC.cpp
cfe/trunk/test/SemaObjC/dealloc.m
Modified: cfe/trunk/include/clang/Basic/DiagnosticGroups.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticGroups.td?rev=197534&r1=197533&r2=197534&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticGroups.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticGroups.td Tue Dec 17 16:44:28 2013
@@ -385,6 +385,7 @@ def ARCRepeatedUseOfWeak : DiagGroup<"ar
[ARCRepeatedUseOfWeakMaybe]>;
def ObjCBridge : DiagGroup<"bridge-cast">;
+def DeallocInCategory:DiagGroup<"dealloc-in-category">;
def SelectorTypeMismatch : DiagGroup<"selector-type-mismatch">;
def Selector : DiagGroup<"selector", [SelectorTypeMismatch]>;
def Protocol : DiagGroup<"protocol">;
Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=197534&r1=197533&r2=197534&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Tue Dec 17 16:44:28 2013
@@ -776,6 +776,9 @@ def err_arc_perform_selector_retains : E
def warn_arc_perform_selector_leaks : Warning<
"performSelector may cause a leak because its selector is unknown">,
InGroup<DiagGroup<"arc-performSelector-leaks">>;
+def warn_dealloc_in_category : Warning<
+"decalloc is being overridden in category">,
+InGroup<DeallocInCategory>;
def err_gc_weak_property_strong_type : Error<
"weak attribute declared on a __strong type property in GC mode">;
def warn_receiver_is_weak : Warning <
Modified: cfe/trunk/lib/Sema/SemaDeclObjC.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclObjC.cpp?rev=197534&r1=197533&r2=197534&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDeclObjC.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclObjC.cpp Tue Dec 17 16:44:28 2013
@@ -3213,6 +3213,14 @@ Decl *Sema::ActOnMethodDeclaration(
ObjCMethod->addAttr(
new (Context) ObjCRequiresSuperAttr(ObjCMethod->getLocation(), Context));
}
+ if (isa<ObjCCategoryImplDecl>(ImpDecl)) {
+ ObjCMethodFamily family = ObjCMethod->getMethodFamily();
+ if (family == OMF_dealloc && IMD && IMD->isOverriding()) {
+ Diag(ObjCMethod->getLocation(), diag::warn_dealloc_in_category)
+ << ObjCMethod->getDeclName();
+ Diag(ImpDecl->getLocation(), diag::note_declared_at);
+ }
+ }
} else {
cast<DeclContext>(ClassDecl)->addDecl(ObjCMethod);
}
Modified: cfe/trunk/test/SemaObjC/dealloc.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/dealloc.m?rev=197534&r1=197533&r2=197534&view=diff
==============================================================================
--- cfe/trunk/test/SemaObjC/dealloc.m (original)
+++ cfe/trunk/test/SemaObjC/dealloc.m Tue Dec 17 16:44:28 2013
@@ -1,5 +1,5 @@
-// RUN: %clang_cc1 -triple x86_64-apple-darwin11 -fsyntax-only -fobjc-arc -fblocks -verify %s
-// RUN: not %clang_cc1 -triple x86_64-apple-darwin11 -fsyntax-only -fobjc-arc -fblocks -fdiagnostics-parseable-fixits %s 2>&1 | FileCheck %s
+// RUN: %clang_cc1 -triple x86_64-apple-darwin11 -fsyntax-only -fobjc-arc -fblocks -Wdealloc-in-category -verify %s
+// RUN: not %clang_cc1 -triple x86_64-apple-darwin11 -fsyntax-only -fobjc-arc -fblocks -Wdealloc-in-category -fdiagnostics-parseable-fixits %s 2>&1 | FileCheck %s
// rdar://11987838
@protocol NSObject
@@ -23,3 +23,19 @@
@end
+// rdar://15397430
+ at interface Base
+- (void)dealloc;
+ at end
+
+ at interface Subclass : Base
+ at end
+
+ at interface Subclass (CAT)
+- (void)dealloc;
+ at end
+
+ at implementation Subclass (CAT) // expected-note {{declared here}}
+- (void)dealloc { // expected-warning {{decalloc is being overridden in category}}
+}
+ at end
More information about the cfe-commits
mailing list