diff options
-rw-r--r-- | lib/Analysis/CheckDeadStores.cpp | 12 | ||||
-rw-r--r-- | test/Analysis/dead-stores.c | 9 |
2 files changed, 17 insertions, 4 deletions
diff --git a/lib/Analysis/CheckDeadStores.cpp b/lib/Analysis/CheckDeadStores.cpp index 4ab6680a78..4acacdf0ce 100644 --- a/lib/Analysis/CheckDeadStores.cpp +++ b/lib/Analysis/CheckDeadStores.cpp @@ -164,11 +164,16 @@ public: 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 @@ public: if (!E->isConstantExpr(Ctx,NULL)) Report(V, DeadInit, V->getLocation(), E->getSourceRange()); } + } } } }; diff --git a/test/Analysis/dead-stores.c b/test/Analysis/dead-stores.c index dce058c02e..0ca289231b 100644 --- a/test/Analysis/dead-stores.c +++ b/test/Analysis/dead-stores.c @@ -77,5 +77,12 @@ int f11() { 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; +} |