This is an archive of the discontinued LLVM Phabricator instance.

[analyzer] Enforce super-region classes for various memory regions through compile-time and run-time type checks.
ClosedPublic

Authored by NoQ on Nov 17 2016, 11:29 PM.

Details

Summary

Put a lot of compile-time and run-time checks on classes of super regions of all SubRegion classes, in order to maintain the existing status quo.
This should make understanding the hierarchy easier, and probably help us catch some bugs.

This is an API-breaking change (we now require explicit casts to specific region sub-classes), but in practice very few checkers are affected.

Diff Detail

Event Timeline

NoQ updated this revision to Diff 78475.Nov 17 2016, 11:29 PM
NoQ retitled this revision from to [analyzer] Enforce super-region classes for various memory regions through compile-time and run-time type checks..
NoQ updated this object.
NoQ added a subscriber: cfe-commits.
a.sidorin edited edge metadata.Nov 18 2016, 6:26 AM

Hi Artem!
I like this change mostly but I also have some remarks.

include/clang/StaticAnalyzer/Core/PathSensitive/MemRegion.h
1279

I think we should perform a cast<> to SubRegion internally in order to keep API simple and do not force clients to introduce casts in their code. This will still allow us to keep nice suggestions about SubRegions/MemSpaces in our hierarchy.

1347

Maybe we should give types and paramers some more meaningful names as a part of refactoring? At least, the number in A1 is not needed now.

xazax.hun edited edge metadata.Nov 23 2016, 5:44 AM

In general I really like this change. See some of my comments inline.

include/clang/StaticAnalyzer/Core/PathSensitive/MemRegion.h
1279

I prefer having a stricter static type.

1347

Agreed.

include/clang/StaticAnalyzer/Core/PathSensitive/Store.h
238

Shouldn't the return value be at least a SubRegion as well?

lib/StaticAnalyzer/Core/ExprEngineCXX.cpp
492

Maybe using getRegionAs would be shorter?

lib/StaticAnalyzer/Core/Store.cpp
439

Also consider getRegionAs.

NoQ updated this revision to Diff 79537.Nov 29 2016, 4:29 AM
NoQ edited edge metadata.
NoQ marked 5 inline comments as done.

Thanks for the comments!
Addressed.

include/clang/StaticAnalyzer/Core/PathSensitive/MemRegion.h
1279

I also believe in "static > dynamic" when it comes to type checks.

1347

Hmm, should we turn this into a proper variadic function then?

include/clang/StaticAnalyzer/Core/PathSensitive/Store.h
238

Yep!

This revision was automatically updated to reflect the committed changes.