diff options
author | Ted Kremenek <kremenek@apple.com> | 2008-07-25 04:47:34 +0000 |
---|---|---|
committer | Ted Kremenek <kremenek@apple.com> | 2008-07-25 04:47:34 +0000 |
commit | fc7ff5540412f8003024e1b4940fb8408dff2ca6 (patch) | |
tree | 54aca61ae4389157b470679eac26b3b0b16117cd /lib/Analysis/CheckDeadStores.cpp | |
parent | 73798892751e378cbcdef43579c1d41685091fd0 (diff) |
Don't emit 'dead initialization' warnings for variables marked 'unused'.
This fixes PR 2573: http://llvm.org/bugs/show_bug.cgi?id=2573
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@54009 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Analysis/CheckDeadStores.cpp')
-rw-r--r-- | lib/Analysis/CheckDeadStores.cpp | 12 |
1 files changed, 9 insertions, 3 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()); } + } } } }; |