[PATCH] D126481: [analyzer] Handle SymbolCast in SValBuilder

Gabor Marton via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Sep 27 02:17:56 PDT 2022


martong added a comment.

> Assume we have `(int)(short)(int x)`. `VisitSymbolCast` will try to get the constant recursively in the next order:
>
> - `(short)(int x)`
> - `(int x)`
>
> And here is my concern. Whether it is correct to get the range for `int x` and consider it as a correct simplification of `(int)(short)(int x)`. IMO it can't be simplified like that. It should go through the set of conventions and intersections.

I agree that it is not correct to do that if there is a **range** associated for the castee symbol, in those cases we should consult with the range based solver. However, this patch handles the case when a **constant** value is associated to the castee. And in that case, this ought to be correct, the cast is handled properly via these functions:  `SValBuilder::evalCast` -> `EvalCastVisitor::VisitNonLocConcreteInt` -> `APSIntType::apply`.

Generally, the `Simplifier::Visit` functions should return a simplified symbol only if during the visitation we could find a constant value associated to any of the visited nodes, it does constant folding. If we simplify with a symbol that is constrained into a range and not into a simple value, then there is a bug, we should fix that.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D126481



More information about the cfe-commits mailing list