Szelethus added reviewers: gamesh411, NoQ.
Szelethus added subscribers: gamesh411, NoQ.
Szelethus added a comment.

+ @gamesh411 as he took over this checker before I commited it on his behalf, 
+@NoQ because he is far more knowledgeable about this part of the analyzer.



================
Comment at: 
clang/lib/StaticAnalyzer/Checkers/EnumCastOutOfRangeChecker.cpp:121-122
   // Check if any of the enum values possibly match.
   bool PossibleValueMatch = llvm::any_of(
       DeclValues, ConstraintBasedEQEvaluator(C, *ValueToCast));
 
----------------
So this is where the assertion comes from, and will eventually lead to 
`SValBuilder::evalEQ`, which calls `SValBuilder::evalBinOp`, where this will 
fire on line 427:
```
assert(op == BO_Add);
```
Seems like this happens because `unused`'s value in your testcase will be 
retrieved as a `Loc`, while the values in the enum are (correctly) `NonLoc`, 
and `SValBuilder::evalBinOp` thinks this is some sort of pointer arithmetic (`5 
+ ptr` etc).

How about instead of checking for LValueToRValue cast, we check whether 
`ValueToCast` is `Loc`, and bail out if so? That sounds like a more general 
solution, but I didn't sit atop of this for hours.


Repository:
  rC Clang

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D66014/new/

https://reviews.llvm.org/D66014



_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to