<div dir="ltr"><br><br><div class="gmail_quote">On Mon, Oct 20, 2008 at 2:06 PM, Ted Kremenek <span dir="ltr"><<a href="mailto:kremenek@apple.com">kremenek@apple.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<div class="Ih2E3d"><br>
On Oct 19, 2008, at 10:05 PM, Zhongxing Xu wrote:<br>
<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
As a more direct example, consider code<br>
<br>
int a[10];<br>
a[1] = 3;<br>
<br>
When we visit a[1], we evaluate a's rvalue. In VisitDeclRefExpr, we first get a's lvalue loc::MemRegionVal(a's region), then do a load on it. We expect to load loc::MemRegionVal(a's region) from itself. Then a ImplicitCast will convert it to a pointer to a's first element.<br>

</blockquote>
<br></div>
Part of my confusion is that BasicStore doesn't model arrays.  We cannot expect to model array bindings using the simple VarDecl to SVal binding in BasicStore.  A "GetSVal" on a VarDecl with an array type should just return UnknownVal, since we don't have "element-sensitivity" in BasicStore.</blockquote>
<div><br>OK. This is reasonable. I removed the special handling of array VarDecl in the BasicStore. Now both 'a' and '*p' will evaluate to UnknownVal. Because GetSVal will return UnknownVal now.<br><br>On the other hand, do you agree the special handling in RegionStore? My intention is this: let both rvalue and lvalue of an array variable be loc::MemRegionVal(its region). Then the ImplicitCast cast this to loc::MemRegionVal(first element's region).<br>
 </div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><br>
<br>
I think I see your point, but I'm not (completely) convinced it is the right approach to do this in the store, as it really seems to be an issue of syntax and performing the right conversions in GRExprEngine.  VisitLValue is called on "a[1]", and "Visit" is called on "a" (returning its rvalue).  The AST dump of the assignment looks like this:<br>

<br>
  (BinaryOperator 0xd07920 <line:3:3, col:10> 'int' '='<br>
    (ArraySubscriptExpr 0xd078e0 <col:3, col:6> 'int'<br>
      (ImplicitCastExpr 0xd078d0 <col:3> 'int *'<br>
        (DeclRefExpr 0xd07870 <col:3> 'int [10]' Var='a' 0xd07820))<br>
      (IntegerLiteral 0xd07890 <col:5> 'int' 1))<br>
    (IntegerLiteral 0xd07900 <col:10> 'int' 3)))<br>
<br>
Do you think it seems more reasonable for VisitCast to specially handle the case of casting an array type to a pointer?  One possible solution in this case would be to have VisitCast invoke VisitLValue on its subexpression when performing such a cast.  I'm not certain if this is the right thing to do.<br>

</blockquote><div><br>We'd better not invode VisitLValue in VisitCast, because the whole ImplicitCastExpr is used in an rvalue context (as the base of the ArraySubscriptExpr).<br><br>As I said above, we do the usual Visit in VisitCast, get loc::MemRegionVal(array's region) through EvalLoad(), with the help of special handling in RegionStore. Then cast this into loc::MemRegionVal(first element's region).<br>
</div></div><br></div>