This is an archive of the discontinued LLVM Phabricator instance.

[analyzer] Use Optional as a return type of StoreManager::castRegion
ClosedPublic

Authored by ASDenysPetrov on May 28 2021, 7:26 AM.

Details

Summary

Make StoreManager::castRegion function usage safier. Replace const MemRegion * with Optional<const MemRegion *>. Simplified one of related test cases due to suggestions in D101635.

Diff Detail

Event Timeline

ASDenysPetrov created this revision.May 28 2021, 7:26 AM
ASDenysPetrov requested review of this revision.May 28 2021, 7:26 AM

Added a simplified test case.

ASDenysPetrov updated this revision to Diff 348554.EditedMay 28 2021, 9:57 AM

Fixed syntax complaints which caused a test fail.

NoQ accepted this revision.May 28 2021, 11:31 PM

Looks great, thanks!

I guess another option is to put loc::MemRegionVal() inside castRegion(). This way the return type Optional<loc::MemRegionVal> unambigously tells that the region is always non-null if present (protected by the assertion in the constructor of loc::MemRegionVal).

This revision is now accepted and ready to land.May 28 2021, 11:31 PM
This revision was landed with ongoing or failed builds.May 29 2021, 5:17 AM
This revision was automatically updated to reflect the committed changes.
ASDenysPetrov added a comment.EditedMay 29 2021, 11:13 AM

@NoQ

I guess another option is to put loc::MemRegionVal() inside castRegion(). This way the return type Optional<loc::MemRegionVal> unambigously tells that the region is always non-null if present (protected by the assertion in the constructor of loc::MemRegionVal).

IMO we should keep const MemRegion * for castRegion as is, since it's intended for cast and should behave as cast. I'd better add a kinda wrapper SValBuilder::getCastedMemRegionVal. WDYT?

NoQ added a comment.May 31 2021, 7:05 PM

WDYT?

Fair point!