[PATCH] D97183: [analyzer] Add NoteTag for smart-ptr get()

Balázs Benics via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Apr 20 06:02:48 PDT 2021


steakhal added a comment.

In D97183#2700810 <https://reviews.llvm.org/D97183#2700810>, @vsavchenko wrote:

> In D97183#2699336 <https://reviews.llvm.org/D97183#2699336>, @steakhal wrote:
>
>> In D97183#2699080 <https://reviews.llvm.org/D97183#2699080>, @RedDocMD wrote:
>>
>>> For the following function:
>>>
>>>   void foo(std::unique_ptr<A> P) {
>>>     A* praw = P.get();
>>>     A* other = praw;
>>>     if (other) {}
>>>     P->foo();
>>>   }
>>>
>>> Where do we expect a note? Where `praw` is initialized, where `other` is initialized or both?
>>
>> I would expect no notes at all, since there is no bug.
>
> According to the existing analyzer logic, there is a bug.  If you check `other` for null, we can conclude that there are circumstances when it is null indeed.

I think we can conclude that `P` must be non-null (since it was unconditionally dereferenced), thus the previous check on the inner pointer and the branch it guards must be dead! This fact deserves a report, you are right. My bad.

In this case, the report should show //how// the inner pointer got bound to the `other`. Thus, we should highlight both assignments.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D97183



More information about the cfe-commits mailing list