summaryrefslogtreecommitdiffstats
path: root/clang/lib/Analysis/ReachableCode.cpp
diff options
context:
space:
mode:
authorTed Kremenek <kremenek@apple.com>2014-03-07 20:51:13 +0000
committerTed Kremenek <kremenek@apple.com>2014-03-07 20:51:13 +0000
commit94d1617a1fbb72fdc0f1ac22bc9f9e6b7ee719b1 (patch)
tree251183a8dee8fd34f9c816c6577f8b9e87f2a1eb /clang/lib/Analysis/ReachableCode.cpp
parent91e45e056b3335ebdfbf15863cc53b7eef2de13d (diff)
downloadbcm5719-llvm-94d1617a1fbb72fdc0f1ac22bc9f9e6b7ee719b1.tar.gz
bcm5719-llvm-94d1617a1fbb72fdc0f1ac22bc9f9e6b7ee719b1.zip
[-Wunreachable-code] Treat constant globals as configuration values in unreachable code heuristics.
This one could possibly be refined even further; e.g. looking at the initializer and see if it is truly a configuration value. llvm-svn: 203283
Diffstat (limited to 'clang/lib/Analysis/ReachableCode.cpp')
-rw-r--r--clang/lib/Analysis/ReachableCode.cpp16
1 files changed, 14 insertions, 2 deletions
diff --git a/clang/lib/Analysis/ReachableCode.cpp b/clang/lib/Analysis/ReachableCode.cpp
index f563cbdc593..47f8f2b90cd 100644
--- a/clang/lib/Analysis/ReachableCode.cpp
+++ b/clang/lib/Analysis/ReachableCode.cpp
@@ -194,8 +194,20 @@ static bool isConfigurationValue(const Stmt *S) {
switch (S->getStmtClass()) {
case Stmt::DeclRefExprClass: {
const DeclRefExpr *DR = cast<DeclRefExpr>(S);
- const EnumConstantDecl *ED = dyn_cast<EnumConstantDecl>(DR->getDecl());
- return ED ? isConfigurationValue(ED->getInitExpr()) : false;
+ const ValueDecl *D = DR->getDecl();
+ if (const EnumConstantDecl *ED = dyn_cast<EnumConstantDecl>(D))
+ return ED ? isConfigurationValue(ED->getInitExpr()) : false;
+ if (const VarDecl *VD = dyn_cast<VarDecl>(D)) {
+ // As a heuristic, treat globals as configuration values. Note
+ // that we only will get here if Sema evaluated this
+ // condition to a constant expression, which means the global
+ // had to be declared in a way to be a truly constant value.
+ // We could generalize this to local variables, but it isn't
+ // clear if those truly represent configuration values that
+ // gate unreachable code.
+ return !VD->hasLocalStorage();
+ }
+ return false;
}
case Stmt::IntegerLiteralClass:
return isExpandedFromConfigurationMacro(S);
OpenPOWER on IntegriCloud