This is an archive of the discontinued LLVM Phabricator instance.

[analyzer] Utility to extract the variable name from a memory region.
AbandonedPublic

Authored by xazax.hun on Jan 6 2016, 6:35 AM.

Details

Summary

This patch adds a small utility to extract variable name from a memory region.
This patch does not contain any test or user yet.
There are however two differential revisions that needs similar functionality. It would be great to decide what implementation to use and make it available as a general utility.

The two potential users: http://reviews.llvm.org/D12761 and http://reviews.llvm.org/D15227

Diff Detail

Event Timeline

xazax.hun updated this revision to Diff 44116.Jan 6 2016, 6:35 AM
xazax.hun retitled this revision from to [analyzer] Utility to extract the variable name from a memory region..
xazax.hun updated this object.
xazax.hun added subscribers: cfe-commits, dkrupp.
lib/StaticAnalyzer/Core/MemRegion.cpp
586

Isn't calling getDecl() and getName() afterwards identical to printPretty()?
Is it possible that a NamedDecl cannot be obtained from a DeclRegion?

588

Regarding the MPI-Checker patch http://reviews.llvm.org/D12761 it is insufficient
if the array index (if obtainable) is not provided.
I think it would be nice if a getVariableName function could always provide as much
information as possible, regarding the passed memory region. Do you actually see a case in
the other implementation where this function fails?
The index is a member variable of the ElementRegion why obtaining that
value cannot fail. If the memory region passed is no ElementRegion then
simply printPretty() is called. I could submit the patch right away if this helps.

xazax.hun added inline comments.Jan 8 2016, 7:13 AM
lib/StaticAnalyzer/Core/MemRegion.cpp
586

The printPretty function copy the name of the variable. First I wanted to avoid any copy and memory allocation, but I realized this utility will probably only be used for diagnostics which is the exceptional case, I think allocations should not cause any performance problem here.

But you are right printPretty is almost identical except for FieldRegions, where it also try to print the super region.
I checked and DeclRegion has 3 superclasses, all of them should contain NamedDecls, so that check should never fail.

588

In this case I think you should commit your version.

xazax.hun abandoned this revision.Jan 11 2016, 3:14 AM