Hello!

On Wed, May 04, 2011 at 02:29:32PM +0800, haihao shen wrote:
> I found CIL treats the following two functions differently.

> void loop_test1()
>     while((get_a()<1) && (get_b()<1))

> void loop_test2()
>     while(!(get_a()<1) && !(get_b()<1))

        Your conditions that control the `while'-loops in loop_test1()
and loop_test2() are different and they have different CFG
representations.


> Does CIL consider the complete of partial logic expression, e.g., !(get_a()<1)
> VS. (get_a()<1) ?

        C-standard: `&&' and function calls are sequence points.
Logical operations are per definitionem side-effect free.

Maybe, I have missed your point, but I do not see a mistake in my
CIL's output of your test file with `--domakeCFG'.  (Parts shown here
after manual reformatting and renaming of the temporary variables.)


void
loop_test1(void)
{
    int tmp_a;
    int tmp_b;

    while (1)
    {
        tmp_a = get_a();
        if (tmp_a < 1)
        {
            tmp_b = get_b();
            if (!(tmp_b < 1))
            {
                goto while_break;
            }
        }
        else
        {
            goto while_break;
        }

        a++;
        b++;
    }
 while_break: /* CIL Label */ ;
}


void
loop_test2(void)
{
    int tmp_a;
    int tmp_b;

    while (1)
    {
        tmp_a = get_a();
        if (tmp_a < 1)
        {
            goto while_break;
        }
        else
        {
            tmp_b = get_b();
            if (tmp_b < 1)
            {
                goto while_break;
            }
        }

        a--;
        b--;
    }
 while_break: /* CIL Label */ ;
}


/Chris

------------------------------------------------------------------------------
WhatsUp Gold - Download Free Network Management Software
The most intuitive, comprehensive, and cost-effective network 
management toolset available today.  Delivers lowest initial 
acquisition cost and overall TCO of any competing solution.
http://p.sf.net/sfu/whatsupgold-sd
_______________________________________________
CIL-users mailing list
CIL-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/cil-users

Reply via email to