[PATCH] D104616: [analyzer][WIP] Model comparision methods of std::unique_ptr

Valeriy Savchenko via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Jun 21 01:28:11 PDT 2021


vsavchenko added a comment.

In D104616#2829705 <https://reviews.llvm.org/D104616#2829705>, @RedDocMD wrote:

> The only method that I think can be realistically modelled is `==` (and thus `!=`). If both the operands refer to the same `unique_ptr`, we know `==` returns true. If they are not the same, the only way `==` can return true if the two smart pointers were initialized from the //same// raw pointer. This is of course a fatal bug in itself. So perhaps we can ignore this case and only consider the first case.
> The ordering operators I guess can't be handled because there is no way to statically tell in general the address of some value. We have the following deductions, nevertheless, mathematically:
> Let `ptr1` and `ptr2` be two `std::unique_ptr` objects.
> If `(ptr1 == ptr2)` is true:
>
> - `ptr1 < ptr2` is false
> - `ptr1 > ptr2` is false
> - `ptr1 <= ptr2` is true
> - `ptr1 >= ptr2` is true
>
> If `(ptr1 == ptr2)` is false, we can't say anything really.

Sounds good to me!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104616



More information about the cfe-commits mailing list