@@ -59,7 +59,8 @@ class ConstraintBasedEQEvaluator {
59
59
// value can be matching.
60
60
class EnumCastOutOfRangeChecker : public Checker <check::PreStmt<CastExpr>> {
61
61
mutable std::unique_ptr<BugType> EnumValueCastOutOfRange;
62
- void reportWarning (CheckerContext &C, const EnumDecl *E) const ;
62
+ void reportWarning (CheckerContext &C, const CastExpr *CE,
63
+ const EnumDecl *E) const ;
63
64
64
65
public:
65
66
void checkPreStmt (const CastExpr *CE, CheckerContext &C) const ;
@@ -78,6 +79,7 @@ EnumValueVector getDeclValuesForEnum(const EnumDecl *ED) {
78
79
} // namespace
79
80
80
81
void EnumCastOutOfRangeChecker::reportWarning (CheckerContext &C,
82
+ const CastExpr *CE,
81
83
const EnumDecl *E) const {
82
84
assert (E && " valid EnumDecl* is expected" );
83
85
if (const ExplodedNode *N = C.generateNonFatalErrorNode ()) {
@@ -98,6 +100,7 @@ void EnumCastOutOfRangeChecker::reportWarning(CheckerContext &C,
98
100
99
101
auto BR = std::make_unique<PathSensitiveBugReport>(*EnumValueCastOutOfRange,
100
102
Msg, N);
103
+ bugreporter::trackExpressionValue (N, CE, *BR);
101
104
BR->addNote (" enum declared here" ,
102
105
PathDiagnosticLocation::create (E, C.getSourceManager ()),
103
106
{E->getSourceRange ()});
@@ -153,13 +156,13 @@ void EnumCastOutOfRangeChecker::checkPreStmt(const CastExpr *CE,
153
156
return ;
154
157
155
158
// Check if any of the enum values possibly match.
156
- bool PossibleValueMatch = llvm::any_of (
157
- DeclValues, ConstraintBasedEQEvaluator (C, *ValueToCast));
159
+ bool PossibleValueMatch =
160
+ llvm::any_of ( DeclValues, ConstraintBasedEQEvaluator (C, *ValueToCast));
158
161
159
162
// If there is no value that can possibly match any of the enum values, then
160
163
// warn.
161
164
if (!PossibleValueMatch)
162
- reportWarning (C, ED);
165
+ reportWarning (C, CE, ED);
163
166
}
164
167
165
168
void ento::registerEnumCastOutOfRangeChecker (CheckerManager &mgr) {
0 commit comments