@@ -59,7 +59,8 @@ class ConstraintBasedEQEvaluator {
5959// value can be matching.
6060class EnumCastOutOfRangeChecker : public Checker <check::PreStmt<CastExpr>> {
6161 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 ;
6364
6465public:
6566 void checkPreStmt (const CastExpr *CE, CheckerContext &C) const ;
@@ -78,6 +79,7 @@ EnumValueVector getDeclValuesForEnum(const EnumDecl *ED) {
7879} // namespace
7980
8081void EnumCastOutOfRangeChecker::reportWarning (CheckerContext &C,
82+ const CastExpr *CE,
8183 const EnumDecl *E) const {
8284 assert (E && " valid EnumDecl* is expected" );
8385 if (const ExplodedNode *N = C.generateNonFatalErrorNode ()) {
@@ -98,6 +100,7 @@ void EnumCastOutOfRangeChecker::reportWarning(CheckerContext &C,
98100
99101 auto BR = std::make_unique<PathSensitiveBugReport>(*EnumValueCastOutOfRange,
100102 Msg, N);
103+ bugreporter::trackExpressionValue (N, CE, *BR);
101104 BR->addNote (" enum declared here" ,
102105 PathDiagnosticLocation::create (E, C.getSourceManager ()),
103106 {E->getSourceRange ()});
@@ -153,13 +156,13 @@ void EnumCastOutOfRangeChecker::checkPreStmt(const CastExpr *CE,
153156 return ;
154157
155158 // 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));
158161
159162 // If there is no value that can possibly match any of the enum values, then
160163 // warn.
161164 if (!PossibleValueMatch)
162- reportWarning (C, ED);
165+ reportWarning (C, CE, ED);
163166}
164167
165168void ento::registerEnumCastOutOfRangeChecker (CheckerManager &mgr) {
0 commit comments