diff options
author | Ted Kremenek <kremenek@apple.com> | 2009-02-09 18:01:00 +0000 |
---|---|---|
committer | Ted Kremenek <kremenek@apple.com> | 2009-02-09 18:01:00 +0000 |
commit | d3098ee64c069a3eff4d2d0a5d655d968c7b5dd2 (patch) | |
tree | 44587b6bee202addec9834206e337522c960b1ae /lib/Analysis/CheckDeadStores.cpp | |
parent | 353ffceafc6bcebd5592cb9d93ea3f9242e5370a (diff) |
Fix PR 2514: Do not flag dead initializations for variables initialized to a constant global variable.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@64149 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Analysis/CheckDeadStores.cpp')
-rw-r--r-- | lib/Analysis/CheckDeadStores.cpp | 17 |
1 files changed, 15 insertions, 2 deletions
diff --git a/lib/Analysis/CheckDeadStores.cpp b/lib/Analysis/CheckDeadStores.cpp index d5e5f4c9b2..504de3c97d 100644 --- a/lib/Analysis/CheckDeadStores.cpp +++ b/lib/Analysis/CheckDeadStores.cpp @@ -195,8 +195,21 @@ public: // If x is EVER assigned a new value later, don't issue // a warning. This is because such initialization can be // due to defensive programming. - if (!E->isConstantInitializer(Ctx)) - Report(V, DeadInit, V->getLocation(), E->getSourceRange()); + if (E->isConstantInitializer(Ctx)) + return; + + // Special case: check for initializations from constant + // variables. + // + // e.g. extern const int MyConstant; + // int x = MyConstant; + // + if (DeclRefExpr *DRE=dyn_cast<DeclRefExpr>(E->IgnoreParenCasts())) + if (VarDecl *VD = dyn_cast<VarDecl>(DRE->getDecl())) + if (VD->hasGlobalStorage() && + VD->getType().isConstQualified()) return; + + Report(V, DeadInit, V->getLocation(), E->getSourceRange()); } } } |