summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFariborz Jahanian <fjahanian@apple.com>2013-12-17 22:44:28 +0000
committerFariborz Jahanian <fjahanian@apple.com>2013-12-17 22:44:28 +0000
commit7e350d23b2159408029dd6608ef3f659f3d46d62 (patch)
treeaa8485b65751ab744437e762fe25bff27da86ea5
parent81e6fccbd72ac4be2be9ad014d78cf0c09e5a1bb (diff)
downloadbcm5719-llvm-7e350d23b2159408029dd6608ef3f659f3d46d62.tar.gz
bcm5719-llvm-7e350d23b2159408029dd6608ef3f659f3d46d62.zip
Objctive-C. warn if dealloc is being overridden in
a category implementation. // rdar://15397430 llvm-svn: 197534
-rw-r--r--clang/include/clang/Basic/DiagnosticGroups.td1
-rw-r--r--clang/include/clang/Basic/DiagnosticSemaKinds.td3
-rw-r--r--clang/lib/Sema/SemaDeclObjC.cpp8
-rw-r--r--clang/test/SemaObjC/dealloc.m20
4 files changed, 30 insertions, 2 deletions
diff --git a/clang/include/clang/Basic/DiagnosticGroups.td b/clang/include/clang/Basic/DiagnosticGroups.td
index 1be01a2ed49..1c69e0075fb 100644
--- a/clang/include/clang/Basic/DiagnosticGroups.td
+++ b/clang/include/clang/Basic/DiagnosticGroups.td
@@ -385,6 +385,7 @@ def ARCRepeatedUseOfWeak : DiagGroup<"arc-repeated-use-of-weak",
[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">;
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 19456297f24..d257e175018 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -776,6 +776,9 @@ def err_arc_perform_selector_retains : Error<
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 <
diff --git a/clang/lib/Sema/SemaDeclObjC.cpp b/clang/lib/Sema/SemaDeclObjC.cpp
index 9f50a207c1a..d536f33c085 100644
--- a/clang/lib/Sema/SemaDeclObjC.cpp
+++ b/clang/lib/Sema/SemaDeclObjC.cpp
@@ -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);
}
diff --git a/clang/test/SemaObjC/dealloc.m b/clang/test/SemaObjC/dealloc.m
index 59218d2d073..4e61424e686 100644
--- a/clang/test/SemaObjC/dealloc.m
+++ b/clang/test/SemaObjC/dealloc.m
@@ -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
+@interface Base
+- (void)dealloc;
+@end
+
+@interface Subclass : Base
+@end
+
+@interface Subclass (CAT)
+- (void)dealloc;
+@end
+
+@implementation Subclass (CAT) // expected-note {{declared here}}
+- (void)dealloc { // expected-warning {{decalloc is being overridden in category}}
+}
+@end
OpenPOWER on IntegriCloud