[cfe-commits] r138730 - in /cfe/trunk: include/clang/Basic/DiagnosticSemaKinds.td include/clang/Basic/IdentifierTable.h include/clang/Sema/Sema.h lib/AST/DeclObjC.cpp lib/Analysis/CocoaConventions.cpp lib/Basic/IdentifierTable.cpp lib/Sema/Sema.cpp lib/Sema/SemaDecl.cpp lib/Sema/SemaDeclObjC.cpp lib/Sema/SemaExprObjC.cpp test/SemaObjC/warn-missing-super.m

Nico Weber nicolasweber at gmx.de
Sun Aug 28 15:35:17 PDT 2011


Author: nico
Date: Sun Aug 28 17:35:17 2011
New Revision: 138730

URL: http://llvm.org/viewvc/llvm-project?rev=138730&view=rev
Log:
Warn on missing [super finalize] calls.

This matches gcc's logic. Second half of PR10661.


Modified:
    cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
    cfe/trunk/include/clang/Basic/IdentifierTable.h
    cfe/trunk/include/clang/Sema/Sema.h
    cfe/trunk/lib/AST/DeclObjC.cpp
    cfe/trunk/lib/Analysis/CocoaConventions.cpp
    cfe/trunk/lib/Basic/IdentifierTable.cpp
    cfe/trunk/lib/Sema/Sema.cpp
    cfe/trunk/lib/Sema/SemaDecl.cpp
    cfe/trunk/lib/Sema/SemaDeclObjC.cpp
    cfe/trunk/lib/Sema/SemaExprObjC.cpp
    cfe/trunk/test/SemaObjC/warn-missing-super.m

Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=138730&r1=138729&r2=138730&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Sun Aug 28 17:35:17 2011
@@ -573,6 +573,9 @@
 def warn_objc_missing_super_dealloc : Warning<
   "method possibly missing a [super dealloc] call">,
   InGroup<ObjCMissingSuperCalls>;
+def warn_objc_missing_super_finalize : Warning<
+  "method possibly missing a [super finalize] call">,
+  InGroup<ObjCMissingSuperCalls>;
 def warn_undeclared_selector : Warning<
   "undeclared selector %0">, InGroup<UndeclaredSelector>, DefaultIgnore;
 def warn_implicit_atomic_property : Warning<

Modified: cfe/trunk/include/clang/Basic/IdentifierTable.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/IdentifierTable.h?rev=138730&r1=138729&r2=138730&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/IdentifierTable.h (original)
+++ cfe/trunk/include/clang/Basic/IdentifierTable.h Sun Aug 28 17:35:17 2011
@@ -487,6 +487,7 @@
   // selector with the given name.
   OMF_autorelease,
   OMF_dealloc,
+  OMF_finalize,
   OMF_release,
   OMF_retain,
   OMF_retainCount,

Modified: cfe/trunk/include/clang/Sema/Sema.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/Sema.h?rev=138730&r1=138729&r2=138730&view=diff
==============================================================================
--- cfe/trunk/include/clang/Sema/Sema.h (original)
+++ cfe/trunk/include/clang/Sema/Sema.h Sun Aug 28 17:35:17 2011
@@ -493,6 +493,9 @@
   /// A flag that is set when parsing a -dealloc method and no [super dealloc]
   /// call was found yet.
   bool ObjCShouldCallSuperDealloc;
+  /// A flag that is set when parsing a -finalize method and no [super finalize]
+  /// call was found yet.
+  bool ObjCShouldCallSuperFinalize;
 
   /// \brief The set of declarations that have been referenced within
   /// a potentially evaluated expression.

Modified: cfe/trunk/lib/AST/DeclObjC.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/DeclObjC.cpp?rev=138730&r1=138729&r2=138730&view=diff
==============================================================================
--- cfe/trunk/lib/AST/DeclObjC.cpp (original)
+++ cfe/trunk/lib/AST/DeclObjC.cpp Sun Aug 28 17:35:17 2011
@@ -446,6 +446,7 @@
 
   // These selectors have a conventional meaning only for instance methods.
   case OMF_dealloc:
+  case OMF_finalize:
   case OMF_retain:
   case OMF_release:
   case OMF_autorelease:

Modified: cfe/trunk/lib/Analysis/CocoaConventions.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/CocoaConventions.cpp?rev=138730&r1=138729&r2=138730&view=diff
==============================================================================
--- cfe/trunk/lib/Analysis/CocoaConventions.cpp (original)
+++ cfe/trunk/lib/Analysis/CocoaConventions.cpp Sun Aug 28 17:35:17 2011
@@ -40,6 +40,7 @@
   case OMF_None:
   case OMF_autorelease:
   case OMF_dealloc:
+  case OMF_finalize:
   case OMF_release:
   case OMF_retain:
   case OMF_retainCount:

Modified: cfe/trunk/lib/Basic/IdentifierTable.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/IdentifierTable.cpp?rev=138730&r1=138729&r2=138730&view=diff
==============================================================================
--- cfe/trunk/lib/Basic/IdentifierTable.cpp (original)
+++ cfe/trunk/lib/Basic/IdentifierTable.cpp Sun Aug 28 17:35:17 2011
@@ -392,6 +392,7 @@
   if (sel.isUnarySelector()) {
     if (name == "autorelease") return OMF_autorelease;
     if (name == "dealloc") return OMF_dealloc;
+    if (name == "finalize") return OMF_finalize;
     if (name == "release") return OMF_release;
     if (name == "retain") return OMF_retain;
     if (name == "retainCount") return OMF_retainCount;

Modified: cfe/trunk/lib/Sema/Sema.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/Sema.cpp?rev=138730&r1=138729&r2=138730&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/Sema.cpp (original)
+++ cfe/trunk/lib/Sema/Sema.cpp Sun Aug 28 17:35:17 2011
@@ -85,6 +85,7 @@
     IdResolver(pp.getLangOptions()), CXXTypeInfoDecl(0), MSVCGuidDecl(0),
     GlobalNewDeleteDeclared(false), 
     ObjCShouldCallSuperDealloc(false),
+    ObjCShouldCallSuperFinalize(false),
     TUKind(TUKind),
     NumSFINAEErrors(0), SuppressAccessChecking(false), 
     AccessCheckingSFINAE(false), InNonInstantiationSFINAEContext(false),

Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=138730&r1=138729&r2=138730&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Sun Aug 28 17:35:17 2011
@@ -6674,12 +6674,18 @@
       Diag(MD->getLocEnd(), diag::warn_objc_missing_super_dealloc);
       ObjCShouldCallSuperDealloc = false;
     }
+    if (ObjCShouldCallSuperFinalize) {
+      Diag(MD->getLocEnd(), diag::warn_objc_missing_super_finalize);
+      ObjCShouldCallSuperFinalize = false;
+    }
   } else {
     return 0;
   }
 
   assert(!ObjCShouldCallSuperDealloc && "This should only be set for "
          "ObjC methods, which should have been handled in the block above.");
+  assert(!ObjCShouldCallSuperFinalize && "This should only be set for "
+         "ObjC methods, which should have been handled in the block above.");
 
   // Verify and clean out per-function state.
   if (Body) {

Modified: cfe/trunk/lib/Sema/SemaDeclObjC.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclObjC.cpp?rev=138730&r1=138729&r2=138730&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDeclObjC.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclObjC.cpp Sun Aug 28 17:35:17 2011
@@ -162,6 +162,7 @@
   switch (family) {
   case OMF_None:
   case OMF_dealloc:
+  case OMF_finalize:
   case OMF_retain:
   case OMF_release:
   case OMF_autorelease:
@@ -267,6 +268,7 @@
 
     case OMF_None:
     case OMF_dealloc:
+    case OMF_finalize:
     case OMF_alloc:
     case OMF_init:
     case OMF_mutableCopy:
@@ -287,14 +289,16 @@
                                           dyn_cast<NamedDecl>(IMD), 
                                           MDecl->getLocation(), 0);
 
-    // If this is "dealloc", set some bit here.
+    // If this is "dealloc" or "finalize", set some bit here.
     // Then in ActOnSuperMessage() (SemaExprObjC), set it back to false.
     // Finally, in ActOnFinishFunctionBody() (SemaDecl), warn if flag is set.
     // Only do this if the current class actually has a superclass.
-    if (IC->getSuperClass())
+    if (IC->getSuperClass()) {
       ObjCShouldCallSuperDealloc = 
         !Context.getLangOptions().ObjCAutoRefCount &&      
         MDecl->getMethodFamily() == OMF_dealloc;
+      ObjCShouldCallSuperFinalize = MDecl->getMethodFamily() == OMF_finalize;
+    }
   }
 }
 
@@ -1256,6 +1260,7 @@
   case OMF_release:
   case OMF_autorelease:
   case OMF_dealloc:
+  case OMF_finalize:
   case OMF_retainCount:
   case OMF_self:
   case OMF_performSelector:
@@ -2637,6 +2642,7 @@
     case OMF_None:
     case OMF_copy:
     case OMF_dealloc:
+    case OMF_finalize:
     case OMF_mutableCopy:
     case OMF_release:
     case OMF_retainCount:

Modified: cfe/trunk/lib/Sema/SemaExprObjC.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExprObjC.cpp?rev=138730&r1=138729&r2=138730&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaExprObjC.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExprObjC.cpp Sun Aug 28 17:35:17 2011
@@ -203,6 +203,7 @@
     case OMF_None:
     case OMF_alloc:
     case OMF_copy:
+    case OMF_finalize:
     case OMF_init:
     case OMF_mutableCopy:
     case OMF_new:
@@ -977,6 +978,8 @@
   if (Method->isInstanceMethod()) {
     if (Sel.getMethodFamily() == OMF_dealloc)
       ObjCShouldCallSuperDealloc = false;
+    if (Sel.getMethodFamily() == OMF_finalize)
+      ObjCShouldCallSuperFinalize = false;
 
     // Since we are in an instance method, this is an instance
     // message to the superclass instance.
@@ -1418,6 +1421,7 @@
     case OMF_None:
     case OMF_alloc:
     case OMF_copy:
+    case OMF_finalize:
     case OMF_mutableCopy:
     case OMF_new:
     case OMF_self:

Modified: cfe/trunk/test/SemaObjC/warn-missing-super.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/warn-missing-super.m?rev=138730&r1=138729&r2=138730&view=diff
==============================================================================
--- cfe/trunk/test/SemaObjC/warn-missing-super.m (original)
+++ cfe/trunk/test/SemaObjC/warn-missing-super.m Sun Aug 28 17:35:17 2011
@@ -8,31 +8,43 @@
 - (void)dealloc {
   // Root class, shouldn't warn
 }
+- (void)finalize {
+  // Root class, shouldn't warn
+}
 @end
 
 @interface Subclass1 : NSObject
 - (void)dealloc;
+- (void)finalize;
 @end
 
 @implementation Subclass1
 - (void)dealloc {
 }
+- (void)finalize {
+}
 @end
 
 @interface Subclass2 : NSObject
 - (void)dealloc;
+- (void)finalize;
 @end
 
 @implementation Subclass2
 - (void)dealloc {
   [super dealloc];  // Shouldn't warn
 }
+- (void)finalize {
+  [super finalize];  // Shouldn't warn
+}
 @end
 
 // RUN: %clang_cc1 -fsyntax-only %s 2>&1 | FileCheck %s
-// CHECK: warn-missing-super.m:19:1: warning: method possibly missing a [super dealloc] call
-// CHECK: 1 warning generated.
+// CHECK: warn-missing-super.m:23:1: warning: method possibly missing a [super dealloc] call
+// CHECK: warn-missing-super.m:25:1: warning: method possibly missing a [super finalize] call
+// CHECK: 2 warnings generated.
 
 // RUN: %clang_cc1 -fsyntax-only -triple x86_64-apple-darwin10 -fobjc-nonfragile-abi -fobjc-arc %s 2>&1 | FileCheck --check-prefix=CHECK-ARC %s
-// CHECK-ARC: warn-missing-super.m:28:4: error: ARC forbids explicit message send of 'dealloc'
-// CHECK-ARC: 1 error generated.
+// CHECK-ARC: warn-missing-super.m:25:1: warning: method possibly missing a [super finalize] call
+// CHECK-ARC: warn-missing-super.m:35:4: error: ARC forbids explicit message send of 'dealloc'
+// CHECK-ARC: 1 warning and 1 error generated.





More information about the cfe-commits mailing list