[PATCH] D89055: [analyzer] Wrong type cast occures during pointer dereferencing after type punning

Denys Petrov via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Sat Oct 17 16:20:48 PDT 2020


ASDenysPetrov added a comment.

@NoQ

> The new code should obviously be restricted into evalCastFromLoc() because if it's a region it's a Loc.

The first I tryed was `evalCastFromLoc()`, but it turned out that `SVal` which binds to a pointer can be `NonLoc` as well through violation of pointing levels.
Look here:

  void foo(int** p) { // here is a two-level pointer
     *(int*)p = 42; // pretend as a one-level pointer, dereference it and assign a number
     *p; // dereferencing once gives a `nonloc::ConcreteInt`
  }
  
  P.S. I can have miscomprehension of this, due to a lack of experience, but this is what I observed.

> Shouldn't we do `castRegion()` unconditionally,

I've also tryed and got 10+ tests unpassed. Didn't dig deeper, just refused this idea.

> Can we also use `evalCast()` ?

Do you mean to move `castRegion()` to `evalCast()` instead of `dispatchCast()`. I can investigate this.


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

https://reviews.llvm.org/D89055



More information about the cfe-commits mailing list