diff options
author | Ted Kremenek <kremenek@apple.com> | 2010-09-09 00:40:40 +0000 |
---|---|---|
committer | Ted Kremenek <kremenek@apple.com> | 2010-09-09 00:40:40 +0000 |
commit | 4d3175c1e5a44251ea97b0c81e80f060629d9c08 (patch) | |
tree | 5b2386ccaface278314b2ea55997683a7cfdf2c8 /lib/Checker/GRExprEngine.cpp | |
parent | 81979822cbf6347116d06dac0e5b06c451bcff05 (diff) |
Static analyzer fix: <rdar://problem/5880430> Switch on enum should not consider default case live if all enum values are covered
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@113457 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Checker/GRExprEngine.cpp')
-rw-r--r-- | lib/Checker/GRExprEngine.cpp | 21 |
1 files changed, 18 insertions, 3 deletions
diff --git a/lib/Checker/GRExprEngine.cpp b/lib/Checker/GRExprEngine.cpp index 1c8a2d61b9..c11785a711 100644 --- a/lib/Checker/GRExprEngine.cpp +++ b/lib/Checker/GRExprEngine.cpp @@ -1561,9 +1561,24 @@ void GRExprEngine::ProcessSwitch(GRSwitchNodeBuilder& builder) { } while (true); } - // If we reach here, than we know that the default branch is - // possible. - if (defaultIsFeasible) builder.generateDefaultCaseNode(DefaultSt); + if (!defaultIsFeasible) + return; + + // If we have switch(enum value), the default branch is not + // feasible if all of the enum constants not covered by 'case:' statements + // are not feasible values for the switch condition. + // + // Note that this isn't as accurate as it could be. Even if there isn't + // a case for a particular enum value as long as that enum value isn't + // feasible then it shouldn't be considered for making 'default:' reachable. + const SwitchStmt *SS = builder.getSwitch(); + const Expr *CondExpr = SS->getCond()->IgnoreParenImpCasts(); + if (CondExpr->getType()->getAs<EnumType>()) { + if (SS->isAllEnumCasesCovered()) + return; + } + + builder.generateDefaultCaseNode(DefaultSt); } void GRExprEngine::ProcessCallEnter(GRCallEnterNodeBuilder &B) { |