]> granicus.if.org Git - clang/commitdiff
Enhance the unused ivar checker to not consider an ivar to be accidentally unused
authorTed Kremenek <kremenek@apple.com>
Thu, 25 Feb 2010 03:26:55 +0000 (03:26 +0000)
committerTed Kremenek <kremenek@apple.com>
Thu, 25 Feb 2010 03:26:55 +0000 (03:26 +0000)
when it is explicitly marked as unused via __attribute__((unused)).

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@97104 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Checker/CMakeLists.txt
lib/Checker/ObjCUnusedIVarsChecker.cpp [moved from lib/Checker/CheckObjCUnusedIVars.cpp with 92% similarity]
test/Analysis/unused-ivars.m

index 0e95b08d872029ab1e2af80e2268bc3fea8b3a6c..fb771a5f04dd83cc497e973f34d999c1d08fdf83 100644 (file)
@@ -18,7 +18,6 @@ add_clang_library(clangChecker
   CheckDeadStores.cpp
   CheckObjCDealloc.cpp
   CheckObjCInstMethSignature.cpp
-  CheckObjCUnusedIVars.cpp
   CheckSecuritySyntaxOnly.cpp
   CheckSizeofPointer.cpp
   Checker.cpp
@@ -42,6 +41,7 @@ add_clang_library(clangChecker
   NSErrorChecker.cpp
   NoReturnFunctionChecker.cpp
   OSAtomicChecker.cpp
+  ObjCUnusedIVarsChecker.cpp
   PathDiagnostic.cpp
   PointerArithChecker.cpp
   PointerSubChecker.cpp
similarity index 92%
rename from lib/Checker/CheckObjCUnusedIVars.cpp
rename to lib/Checker/ObjCUnusedIVarsChecker.cpp
index f2cf581916321d2a36c75176d9ec387bad00e6f0..04d897aec894978a7caf3956f4117cb0d915baa9 100644 (file)
@@ -1,4 +1,4 @@
-//==- CheckObjCUnusedIVars.cpp - Check for unused ivars ----------*- C++ -*-==//
+//==- ObjCUnusedIVarsChecker.cpp - Check for unused ivars --------*- C++ -*-==//
 //
 //                     The LLVM Compiler Infrastructure
 //
@@ -68,14 +68,14 @@ static void Scan(IvarUsageMap& M, const ObjCContainerDecl* D) {
   for (ObjCContainerDecl::instmeth_iterator I = D->instmeth_begin(),
        E = D->instmeth_end(); I!=E; ++I)
     Scan(M, (*I)->getBody());
-  
-  if (const ObjCImplementationDecl *ID = dyn_cast<ObjCImplementationDecl>(D)) {    
+
+  if (const ObjCImplementationDecl *ID = dyn_cast<ObjCImplementationDecl>(D)) {
     // Scan for @synthesized property methods that act as setters/getters
     // to an ivar.
     for (ObjCImplementationDecl::propimpl_iterator I = ID->propimpl_begin(),
          E = ID->propimpl_end(); I!=E; ++I)
       Scan(M, *I);
-    
+
     // Scan the associated categories as well.
     for (const ObjCCategoryDecl *CD =
           ID->getClassInterface()->getCategoryList(); CD ;
@@ -92,7 +92,7 @@ static void Scan(IvarUsageMap &M, const DeclContext *C, const FileID FID,
        I!=E; ++I)
     if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(*I)) {
       SourceLocation L = FD->getLocStart();
-      if (SM.getFileID(L) == FID)      
+      if (SM.getFileID(L) == FID)
         Scan(M, FD->getBody());
     }
 }
@@ -109,12 +109,12 @@ void clang::CheckObjCUnusedIvar(const ObjCImplementationDecl *D,
 
     const ObjCIvarDecl* ID = *I;
 
-    // Ignore ivars that aren't private.
-    if (ID->getAccessControl() != ObjCIvarDecl::Private)
-      continue;
-
-    // Skip IB Outlets.
-    if (ID->getAttr<IBOutletAttr>())
+    // Ignore ivars that...
+    // (a) aren't private
+    // (b) explicitly marked unused
+    // (c) are iboutlets
+    if (ID->getAccessControl() != ObjCIvarDecl::Private ||
+        ID->getAttr<UnusedAttr>() || ID->getAttr<IBOutletAttr>())
       continue;
 
     M[ID] = Unused;
@@ -122,11 +122,10 @@ void clang::CheckObjCUnusedIvar(const ObjCImplementationDecl *D,
 
   if (M.empty())
     return;
-  
+
   // Now scan the implementation declaration.
   Scan(M, D);
 
-  
   // Any potentially unused ivars?
   bool hasUnused = false;
   for (IvarUsageMap::iterator I = M.begin(), E = M.end(); I!=E; ++I)
@@ -134,10 +133,10 @@ void clang::CheckObjCUnusedIvar(const ObjCImplementationDecl *D,
       hasUnused = true;
       break;
     }
-  
+
   if (!hasUnused)
     return;
-  
+
   // We found some potentially unused ivars.  Scan the entire translation unit
   // for functions inside the @implementation that reference these ivars.
   // FIXME: In the future hopefully we can just use the lexical DeclContext
index 600f0e28e0364a30f06ccb42b4300db1f8f6e0d4..14c43a86c4086fb517b55155bd15006abd83f40c 100644 (file)
@@ -81,3 +81,18 @@ int radar_7254495(RDar7254495 *a) {
   return a->x;
 }
 @end
+
+//===----------------------------------------------------------------------===//
+// <rdar://problem/7353683> - consult attribute((unused)) to silence warnings
+// about unused instance variables
+//===----------------------------------------------------------------------===//
+
+@interface RDar7353683 {
+@private
+  id x __attribute__((unused));
+}
+@end
+
+@implementation RDar7353683
+@end
+