[Cocci] if else not matching

Julia Lawall julia at diku.dk
Tue Jun 30 19:49:56 CEST 2009


On Mon, 29 Jun 2009, Derek M Jones wrote:

> All,
> 
> Sorry for this email but I think I am doing something so basically
> wrong I cannot see it (much more complicated examples such as
> nested if else if match as expected).  I am using version 0.1.8
> and have been staring at this and trying different things for
> several hours.
> 
> I would appreciate if somebody could put me out of my misery and
> point out why the following pattern is not matching against the
> very short C function appended at the end.
> 
> I don't get any warnings (or a --- ifelse)

Thanks for the report.  The problem is that p_2_ie for some reason does 
not get bound.  I suspect that this is due to some over-aggressive 
optimization.  I will look into it.

You can see the problem with the -debug option.  Only the position for the 
if and the variable for the test expression are mentioned in the 
environment that is the result of the match:

-----------------------------------------------------------------------
if_else_1 = 
-----------------------------------------------------------------------
dependencies for rule if_else_1 satisfied:
binding in = []
binding relevant in = []
     transformation info is empty
     binding out = [E_1_ie --> x2;
                   p_1_ie --> poss[(tests/ife.c,f,(3,0),(3,2))]]

julia



> @ if_else_1
> disable neg_if
> @
> expression E_1_ie;
> statement S_1_ie, S_2_ie;
> position p_1_ie, p_2_ie;
> @@
> if at p_1_ie (E_1_ie)
>    S_1_ie
> else at p_2_ie
>    S_2_ie
> @
> 
> script:python @ expr_1_ie << if_else_1.E_1_ie;
>                 loc_1_ie << if_else_1.p_1_ie;
>                 loc_2_ie << if_else_1.p_2_ie;
>               @@
> print "--- ifelse"
> print loc_1_ie[0].line, " ", loc_1_ie[0].column, " ", expr_1_ie
> print loc_2_ie[0].line, " ", loc_2_ie[0].column
> 
> the C input:
> 
> void f(void)
> {
> if (x2)
>    w++;
> else
>    z--;
> }
> 
> -- 
> Derek M. Jones                         tel: +44 (0) 1252 520 667
> Knowledge Software Ltd                 mailto:derek at knosof.co.uk
> Source code analysis                   http://www.knosof.co.uk
> _______________________________________________
> Cocci mailing list
> Cocci at diku.dk
> http://lists.diku.dk/mailman/listinfo/cocci
> (Web access from inside DIKUs LAN only)
> 
> 


More information about the Cocci mailing list