[cfe-dev] [analyzer] - get ElementRegions from MemRegion

Alexander Droste via cfe-dev cfe-dev at lists.llvm.org
Sun Aug 16 01:36:33 PDT 2015


Hi everyone,

I'd like to get all ElementRegions of a MemRegion
passed as an argument to a CallEvent.
The MemRegion represents a fixed size array.

When I pass elements of the array to a function, I get this:
int arr[2];
f(&arr[1]) // element{arr,0 S32b,int*}
f(&arr[0]) // element{arr,1 S32b,int*}

Is it possible to retrieve the single ElementRegions from an array
passed as a whole?
g(arr) // element{arr,0 S32b,int*}, element{arr,1 S32b,int*}

For a single index I tried:
const MemRegion *memRegion = callEvent.getArgSVal(0).getAsRegion();
MemRegionManager *regionManager = memRegion->getMemRegionManager();
SVal idx = ctx.getSValBuilder().makeArrayIndex(1);
auto elementRegion = regionManager->getElementRegion(
     callEvent.getArgExpr(0)->getType(), idx.castAs<NonLoc>(),
     memRegion, ctx.getASTContext());

Logging elementRegion yields:
element{element{arr,0 S32b,int *},1 S32b,int **}

-Alex







More information about the cfe-dev mailing list