[cfe-commits] [PATCH] RegionStore

Eli Friedman eli.friedman at gmail.com
Mon Oct 20 09:54:59 PDT 2008


On Mon, Oct 20, 2008 at 7:15 AM, Zhongxing Xu <xuzhongxing at gmail.com> wrote:
> On Mon, Oct 20, 2008 at 2:06 PM, Ted Kremenek <kremenek at apple.com> wrote:
>> 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.
>>
>
> After examining the code in CodeGen part of clang, now I think this approach

I don't know much about the analysis code, but you definitely need
special handling for casts from an array type to a pointer type; it's
not a normal cast.

In the following example:
int a[10];
int (*p)[10];

a and *p are lvalues.  However, they get promoted to pointers in
almost all contexts (the exceptions being the operands of sizeof and &
operators).  That promotion is done by an ImplicitCastExpr.  The
semantics of the promotion is that it returns the address of the first
element of the array.  So this kind of cast probably needs to be
handled more like an addressof operator rather than a regular cast.
You do need to watch out for cases where the ImplicitCastExpr does
both a cast and a promotion, though.

-Eli



More information about the cfe-commits mailing list