summaryrefslogtreecommitdiffstats
path: root/clang/lib/Checker
diff options
context:
space:
mode:
authorTed Kremenek <kremenek@apple.com>2010-03-18 01:22:39 +0000
committerTed Kremenek <kremenek@apple.com>2010-03-18 01:22:39 +0000
commite174fda979998fb9f49f669b6a4ca2005e770318 (patch)
tree186fac06db4db5fddd5058901879b8964969b5a9 /clang/lib/Checker
parent1bc22f719fb435926410fa60e87093d49de5b9de (diff)
downloadbcm5719-llvm-e174fda979998fb9f49f669b6a4ca2005e770318.tar.gz
bcm5719-llvm-e174fda979998fb9f49f669b6a4ca2005e770318.zip
Tweak dead stores checker to not emit a warning when initialization
a scalar variable with a scalar parameter. This is a form of defensive programming. If the variable is unused, it will be caused by -Wunused-variable. llvm-svn: 98795
Diffstat (limited to 'clang/lib/Checker')
-rw-r--r--clang/lib/Checker/CheckDeadStores.cpp25
1 files changed, 17 insertions, 8 deletions
diff --git a/clang/lib/Checker/CheckDeadStores.cpp b/clang/lib/Checker/CheckDeadStores.cpp
index 31f9390e622..d6ea187957c 100644
--- a/clang/lib/Checker/CheckDeadStores.cpp
+++ b/clang/lib/Checker/CheckDeadStores.cpp
@@ -220,16 +220,25 @@ public:
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 (VarDecl *VD = dyn_cast<VarDecl>(DRE->getDecl())) {
+ // Special case: check for initialization from constant
+ // variables.
+ //
+ // e.g. extern const int MyConstant;
+ // int x = MyConstant;
+ //
if (VD->hasGlobalStorage() &&
- VD->getType().isConstQualified()) return;
+ VD->getType().isConstQualified())
+ return;
+ // Special case: check for initialization from scalar
+ // parameters. This is often a form of defensive
+ // programming. Non-scalars are still an error since
+ // because it more likely represents an actual algorithmic
+ // bug.
+ if (isa<ParmVarDecl>(VD) && VD->getType()->isScalarType())
+ return;
+ }
Report(V, DeadInit, V->getLocation(), E->getSourceRange());
}
OpenPOWER on IntegriCloud