Unexpected evaluation in conditional branch

Dibyendu Majumdar mobile@majumdar.org.uk
Thu Jan 1 00:00:00 GMT 2015


On 27 June 2015 at 22:32, Dibyendu Majumdar <mobile@majumdar.org.uk> wrote:
> On 27 June 2015 at 21:26, Dibyendu Majumdar <mobile@majumdar.org.uk> wrote:
>>> I have scenario where the conditional branch is evaluating the result
>>> of a comparison - one of the operands of the comparison is a function
>>> call. The generated code appears to evaluate the comparison twice -
>>> once for the true branch and once for the false branch - which is not
>>> what I am expecting. I can of course store the result of the
>>> comparison in a local variable and then perform conditional branch on
>>> the variable but I wanted to check whether this behaviour is as
>>> expected.
>>>
>>
>> Sadly even after assigning to a local variable the code I am getting
>> is evaluating the expression twice. Now I get:
>>
>
> Assigning the result of the comparison to a local variable did not
> help. But I was able to workaround the issue by assigning the value of
> the function call to a local variable and then using the variable in a
> comparison. So now I get:
>
>   L->top = &base[(int)2];
>   OP_CALL_luaD_precall_result_2_1 = luaD_precall (L, &base[(int)0], (int)0);
>   if (OP_CALL_luaD_precall_result_2_1 == (int)0) goto
> OP_CALL_if_lua_function_2_2; else goto OP_CALL_else_lua_function_2_3;
>
> OP_CALL_if_lua_function_2_2:
>   (void)luaV_execute (L);
>   goto OP_CALL_done_2_4;
>
> OP_CALL_else_lua_function_2_3:
>   if (OP_CALL_luaD_precall_result_2_1 == (int)1) goto
> OP_CALL_if_C_function_2_5; else goto OP_CALL_done_2_4;
>
>
> This is a serious bug in my view. I was getting weird errors that I
> could not explain - only after spending several hours debugging I was
> able to identify the cause. Basically the condition on an conditional
> branch cannot be evaluated twice.
>

OK I think that the bug was in my code - I was using the same rvalue
in two conditional branches - so apologies for the false alarm.

Regards
Dibyendu



More information about the Jit mailing list