[PATCH] D66014: [analyzer] Avoid unnecessary enum range check on LValueToRValue casts

Kristóf Umann via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Sun Aug 11 15:31:56 PDT 2019


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, + at 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





More information about the cfe-commits mailing list