Hi Jordan,
Actually, I am using the Clang Static Analyzer to do some platform-dependent detection work by developing a checker. The Static Analyzer and my checker are running on an X86-64bit/Linux platform. I’ve set two platform specifications in my checker. So during the evaluation, it can do some platform-dependent detection work by calculation. As a part of my design, given a MemRegion, I need to get its ‘Top Region’ and then to calculate the offset between them. For example:
……
int a = sizeof(long), arr[10][10];
arr[a][3] = 8;
……
For ‘arr[a][3]’, its MemRegion can be represented as ‘&element{element{arr,8 S32b,int [10]},3 S32b,int}’ on an X86-64bit machine. And its Top Region is ‘&arr’. Now I want to calculate the offset as if the code was running on an X86-32bit machine. So ‘&arr[a][3]’ should be ‘&element{element{arr,4 S32b,int [10]},3 S32b,int}’ on that platform, rather than ‘&element{element{arr,8 S32b,int [10]},3 S32b,int}’. In this way, I need to know the SVal for ‘variable a’.
Another related problem in my previous mail post (http://lists.cs.uiuc.edu/pipermail/cfe-dev/2014-April/036205.html) is for pointers. For example:
0 /* example 2 */
1 struct st0 {
2 int i;
3 };
4 struct st1 {
5 int i;
6 struct st0 struct0;
7};
8struct st2 {
9 struct st1 *p;
10 };
11 int main() {
12 struct st1 s1;
13 struct st2 s2;
14 s2.p = &s1;
15 s2.p->struct0.i = 3;
16 }
In fact, the ‘s2.p->struct0.i’ in line 15 should be ‘&s1-> struct0.i’. I want to get the Top Region (&s1) and calculate the offsets between ‘&field_i’ and its Top MemRegion for different platforms. So I tried to use getSuperRegion() repeatedly to get the Top Region starting from the Button MemRegion ‘&field_i’. However, there is a pointer reference along this path. Consequently, if I only use getSuperRegion() all the way, the Top Region will be MemRegion ‘&s2’. Obviously, it isn’t the right Top Region I want. And the right Top Region should be ‘&s1’. So during the upward tracking, if the current MemRegion is a pointer MemRegion, then its pointee MemRegion (the MemRegion which is referred by the pointer) should be achieved. Then I tried to get the pointee MemRegion referred by ‘&s2.p’ via Store (StoreManager.getBinding()). But I got an Undefined SVal. However, the expected SVal should be a MemRegionVal wrapping MemRegion ‘&s1’. So how can I get the pointee MemRegion in such situation?
I’ve been trapped in these problems for weeks. Any help would be greatly appreciated.
Thanks a lot.