[cfe-commits] r58440 - /cfe/trunk/lib/Analysis/GRExprEngine.cpp

Zhongxing Xu xuzhongxing at gmail.com
Thu Oct 30 23:00:55 PDT 2008


On Fri, Oct 31, 2008 at 1:55 PM, Ted Kremenek <kremenek at apple.com> wrote:

>
> On Oct 30, 2008, at 9:44 PM, Zhongxing Xu wrote:
>
> On Fri, Oct 31, 2008 at 12:27 PM, Ted Kremenek <kremenek at apple.com> wrote:
>
>>
>> On Oct 30, 2008, at 7:56 PM, Zhongxing Xu wrote:
>>
>> Hi Ted,
>>>
>>> Would visiting the InitList from right to left lead to some bugs? For
>>> example:
>>>
>>> int x = 3;
>>> int a[3] = {1, x = 1, 2*x+3};
>>>
>>> At last a should be { 1, 1, 5 }. But visit from right to left results {
>>> 1, 1, 9 }
>>>
>>
>> I don't think the order of evaluation is defined (we should consult the
>> standard).  If there is an explicit control-flow dependency between the
>> subexpressions, we should put that explicitly in the CFG.  In that case
>> visiting the subexpressions from right-to-left or left-to-right won't matter
>> (as the expressions will have already been evaluated).
>
>
> Agree.
>
>
> Another thing I thought of is cases like the following:
>
> int a[3] = { x = (y = 2 * x), (x = 2 * y) ? 4 : 5, x };
>
> Here there is a bunch of control-flow, but because of the ? operator the
> expression "(x = 2 * y) ? 4" will always be evaluated first (since it is
> hoisted in the CFG as a block-level expression), even if we did
> left-to-right visitation of the the subexpressions of the InitListExpr.
>  Thus the only way to ensure a fixed order of evaluation is to put it in the
> CFG (i.e., we couldn't do it in GRExprEngine even if we wanted to).
>

Right.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20081031/fb9925d8/attachment.html>


More information about the cfe-commits mailing list