[cfe-commits] r54009 - in /cfe/trunk: lib/Analysis/CheckDeadStores.cpp test/Analysis/dead-stores.c
Ted Kremenek
kremenek at apple.com
Thu Jul 24 21:47:34 PDT 2008
Author: kremenek
Date: Thu Jul 24 23:47:34 2008
New Revision: 54009
URL: http://llvm.org/viewvc/llvm-project?rev=54009&view=rev
Log:
Don't emit 'dead initialization' warnings for variables marked 'unused'.
This fixes PR 2573: http://llvm.org/bugs/show_bug.cgi?id=2573
Modified:
cfe/trunk/lib/Analysis/CheckDeadStores.cpp
cfe/trunk/test/Analysis/dead-stores.c
Modified: cfe/trunk/lib/Analysis/CheckDeadStores.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/CheckDeadStores.cpp?rev=54009&r1=54008&r2=54009&view=diff
==============================================================================
--- cfe/trunk/lib/Analysis/CheckDeadStores.cpp (original)
+++ cfe/trunk/lib/Analysis/CheckDeadStores.cpp Thu Jul 24 23:47:34 2008
@@ -164,11 +164,16 @@
for (ScopedDecl* SD = DS->getDecl(); SD; SD = SD->getNextDeclarator()) {
VarDecl* V = dyn_cast<VarDecl>(SD);
- if (!V) continue;
+
+ if (!V)
+ continue;
if (V->hasLocalStorage())
- if (Expr* E = V->getInit())
- if (!Live(V, AD)) {
+ if (Expr* E = V->getInit()) {
+ // A dead initialization is a variable that is dead after it
+ // is initialized. We don't flag warnings for those variables
+ // marked 'unused'.
+ if (!Live(V, AD) && V->getAttr<UnusedAttr>() == 0) {
// Special case: check for initializations with constants.
//
// e.g. : int x = 0;
@@ -179,6 +184,7 @@
if (!E->isConstantExpr(Ctx,NULL))
Report(V, DeadInit, V->getLocation(), E->getSourceRange());
}
+ }
}
}
};
Modified: cfe/trunk/test/Analysis/dead-stores.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/dead-stores.c?rev=54009&r1=54008&r2=54009&view=diff
==============================================================================
--- cfe/trunk/test/Analysis/dead-stores.c (original)
+++ cfe/trunk/test/Analysis/dead-stores.c Thu Jul 24 23:47:34 2008
@@ -77,5 +77,12 @@
return ++x; // expected-warning{{never read}}
}
-
+int f12a(int y) {
+ int x = y; // expected-warning{{never read}}
+ return 1;
+}
+int f12b(int y) {
+ int x __attribute__((unused)) = y; // no-warning
+ return 1;
+}
More information about the cfe-commits
mailing list