[cfe-commits] r89448 - in /cfe/trunk: lib/Analysis/CheckObjCUnusedIVars.cpp test/Analysis/unused-ivars.m
Ted Kremenek
kremenek at apple.com
Thu Nov 19 20:32:03 PST 2009
Author: kremenek
Date: Thu Nov 19 22:31:57 2009
New Revision: 89448
URL: http://llvm.org/viewvc/llvm-project?rev=89448&view=rev
Log:
Unused ivar checker: ivars referenced by lexically nested functions should not be flagged as unused. Fixes <rdar://problem/7254495>.
Modified:
cfe/trunk/lib/Analysis/CheckObjCUnusedIVars.cpp
cfe/trunk/test/Analysis/unused-ivars.m
Modified: cfe/trunk/lib/Analysis/CheckObjCUnusedIVars.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/CheckObjCUnusedIVars.cpp?rev=89448&r1=89447&r2=89448&view=diff
==============================================================================
--- cfe/trunk/lib/Analysis/CheckObjCUnusedIVars.cpp (original)
+++ cfe/trunk/lib/Analysis/CheckObjCUnusedIVars.cpp Thu Nov 19 22:31:57 2009
@@ -85,6 +85,17 @@
}
}
+static void Scan(IvarUsageMap &M, const DeclContext *C, const FileID FID,
+ SourceManager &SM) {
+ for (DeclContext::decl_iterator I=C->decls_begin(), E=C->decls_end();
+ I!=E; ++I)
+ if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(*I)) {
+ SourceLocation L = FD->getLocStart();
+ if (SM.getFileID(L) == FID)
+ Scan(M, FD->getBody());
+ }
+}
+
void clang::CheckObjCUnusedIvar(const ObjCImplementationDecl *D,
BugReporter &BR) {
@@ -110,10 +121,30 @@
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)
+ if (I->second == Unused) {
+ 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
+ // to go from the ObjCImplementationDecl to the lexically "nested"
+ // C functions.
+ SourceManager &SM = BR.getSourceManager();
+ Scan(M, D->getDeclContext(), SM.getFileID(D->getLocation()), SM);
+
// Find ivars that are unused.
for (IvarUsageMap::iterator I = M.begin(), E = M.end(); I!=E; ++I)
if (I->second == Unused) {
Modified: cfe/trunk/test/Analysis/unused-ivars.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/unused-ivars.m?rev=89448&r1=89447&r2=89448&view=diff
==============================================================================
--- cfe/trunk/test/Analysis/unused-ivars.m (original)
+++ cfe/trunk/test/Analysis/unused-ivars.m Thu Nov 19 22:31:57 2009
@@ -65,3 +65,19 @@
}
@end
+//===----------------------------------------------------------------------===//
+// <rdar://problem/7254495> - ivars referenced by lexically nested functions
+// should not be flagged as unused
+//===----------------------------------------------------------------------===//
+
+ at interface RDar7254495 {
+ at private
+ int x; // no-warning
+}
+ at end
+
+ at implementation RDar7254495
+int radar_7254495(RDar7254495 *a) {
+ return a->x;
+}
+ at end
More information about the cfe-commits
mailing list