This is an archive of the discontinued LLVM Phabricator instance.

[analyzer] Add modeling of Eq operator in smart ptr
ClosedPublic

Authored by vrnithinkumar on Aug 20 2020, 8:06 AM.

Details

Summary

Support for std::unique_ptr>::operator=

Diff Detail

Event Timeline

vrnithinkumar created this revision.Aug 20 2020, 8:06 AM
vrnithinkumar requested review of this revision.Aug 20 2020, 8:06 AM
  • Add assignment to nullptr case
vrnithinkumar edited the summary of this revision. (Show Details)Aug 20 2020, 11:49 AM
NoQ added a comment.Aug 21 2020, 5:53 PM

This looks outright correct to me. I have random suggestions on note text here and there.

clang/test/Analysis/smart-ptr-text-output.cpp
131

I suggest: Null pointer value move-assigned to 'P'.

138

I suggest: Smart pointer 'PToMove' is null; previous value moved to 'P'. Or maybe instead keep the note that the move-checker currently emits?

xazax.hun added inline comments.Aug 22 2020, 9:13 AM
clang/lib/StaticAnalyzer/Checkers/SmartPtrModeling.cpp
353

I'd prefer to call this AssignOp to avoid confusion with ==. While your naming is correct, I always found this nomenclature confusing.

386

I also find the names of the variables confusing.

Instead of ArgRegion what about OtherSmartPtrRegion?
Instead of ArgRegionVal what about OtherInnerPtr?

393

Adding return after every addTransition is a good practive that we should follow.

421

Isn't this the same as the beginning of the note tag above?

I wonder if there is a way to deduplicate this code. Not a huge priority though as I do not have an immediate idea for doing this in a clean way.

vsavchenko added inline comments.Aug 24 2020, 1:04 AM
clang/lib/StaticAnalyzer/Checkers/SmartPtrModeling.cpp
353

IMO it's not a question of preference with this one, EqOp is misleading.

401

The grammar seems off in this one. I think it should be smith like "after being moved to" or "after it was moved to".

clang/test/Analysis/smart-ptr-text-output.cpp
131

+1

vrnithinkumar marked 9 inline comments as done.
vrnithinkumar edited the summary of this revision. (Show Details)
  • Addressing review comments
clang/lib/StaticAnalyzer/Checkers/SmartPtrModeling.cpp
353

Changed to AssignOp

386

Changed to OtherSmartPtrRegion and OtherInnerPtr

393

Added return

401

Changed to "after being moved to"

421

Yes.
The check for bug type is duplicated across all the note tags.

clang/test/Analysis/smart-ptr-text-output.cpp
131

Updated to Null pointer value move-assigned to 'P'

138

Going with first option "Smart pointer 'PToMove' is null; previous value moved to 'P'"

NoQ accepted this revision.Aug 25 2020, 1:14 PM

Looks amazing now.

This revision is now accepted and ready to land.Aug 25 2020, 1:14 PM