[Cocci] 答复: 答复: 答复: 答复: how to write such matching case?

林嘉(程二 福州) linjia at ruijie.com.cn
Wed Feb 12 03:34:44 CET 2014


You mean this?

@forall@
@@
* main(){
   ...when != reg_process_exit_action(...)
}

And my 'main' function is straightforward without flow control

int main(void)
{
    struct AAAA foo;
    struct AAA foo2;
    struct BBB foo3, *p;
    printf("%d\n", sizeof(((struct AAAA*)0)->aa));
    printf("%d %d %d\n", foo.aa.c, foo2.c, foo3.value); 
    memset(p, 0, sizeof(*p));    
    reg_process_exit_action(0, RESTART);    
    return 0;
}



-----邮件原件-----
发件人: Julia Lawall [mailto:julia.lawall at lip6.fr] 
发送时间: 2014年1月28日 15:25
收件人: 林嘉(程二 福州)
抄送: Peter Senna Tschudin; cocci at systeme.lip6.fr
主题: Re: 答复: [Cocci] 答复: 答复: how to write such matching case?



On Tue, 28 Jan 2014, 林嘉(程二 福州) wrote:

> Just like this?
> @@
> @@
> * main(...){
>    ...when != reg_process_exit_action(...) }
> 
> 
> I tried, but it seems does not work...
> 
> I make the function reg...() called in main(), but it still report 
> main()

Probably because there exists a control flow path in which it is not called.  If you want the forall semantics, put forall in between the initial @@

julia


> 
> -----邮件原件-----
> 发件人: Peter Senna Tschudin [mailto:peter.senna at gmail.com]
> 发送时间: 2014年1月27日 22:12
> 收件人: 林嘉(程二 福州)
> 抄送: Julia Lawall; cocci at systeme.lip6.fr
> 主题: Re: [Cocci] 答复: 答复: how to write such matching case?
> 
> You can try:
> 
> @@
> @@
> * main () {
>    ...
>    when != Foo(...)
> }
> 
> This semantic patch will match functions named main that do not 
> contain call to function Foo;
> 
> On Mon, Jan 27, 2014 at 2:55 PM, 林嘉(程二 福州) <linjia at ruijie.com.cn> wrote:
> > Thanks for explain, but if I want to write a simple match, that is 
> > function foo must be called in main() e.g.
> >
> > int main(...)
> > {
> >     ...
> >     Foo(...);
> >     ...
> > }
> >
> > I write it as
> >
> > @@
> > @@
> > main(...) {
> >   <...
> >     when != reg_process_exit_action(...)
> >   ...>
> > }
> >
> > Reports: 53 57
> > Fatal error: exception Failure("minus: parse error:
> >  = File "rgos.cocci", line 6, column 2,  charpos = 53
> >     around = '...>', whole content =   ...>
> > ")
> >
> > What does it mean?
> >
> > By the way, I still don’t know when I should use '<'and'>' and when need not?
> >
> > -----邮件原件-----
> > 发件人: Julia Lawall [mailto:julia.lawall at lip6.fr]
> > 发送时间: 2014年1月27日 20:34
> > 收件人: 林嘉(程二 福州)
> > 抄送: cocci at systeme.lip6.fr
> > 主题: Re: 答复: [Cocci] how to write such matching case?
> >
> > On Mon, 27 Jan 2014, 林嘉(程二 福州) wrote:
> >
> >> I wrote this
> >>
> >> @@
> >> @@
> >> cli_printf(...)
> >> ... when != cli_client_execmd_fail(...)
> >>
> >>
> >> it reports:
> >> Fatal error: exception Failure("False should not be in the final 
> >> result.  Perhaps your rule doesn't contain any +/-/* code, or you 
> >> have a failed dependency.")
> >>
> >>
> >> But i found there is not 'minus' in an example.cocci either....
> >
> > There is a * (indicating a line of interest).  You can use that.  If you use that, you will get an exists semantics for the ... (there exists an execution path that satisfies the property).  Otherwise, you get a foral semantics (all execution paths have to satisfy the property).
> >
> > julia
> >
> >>
> >>
> >> //
> >> //  Add missing pci_dev_put
> >> //
> >> // Target: Linux
> >> // Copyright:  2012 - LIP6/INRIA
> >> // License:  Licensed under ISC. See LICENSE or 
> >> http://www.isc.org/software/license
> >> // Author: Julia Lawall <Julia.Lawall at lip6.fr> // URL:
> >> http://coccinelle.lip6.fr/ // URL: http://coccinellery.org/
> >>
> >> @@
> >> local idexpression x;
> >> expression e;
> >> @@
> >>
> >> *x = pci_get_slot(...)
> >> ... when != true x == NULL
> >>     when != pci_dev_put(x)
> >>     when != e = x
> >>     when != if (x != NULL) {<+... pci_dev_put(x); ...+>} *return 
> >> ...;
> >>
> >>
> >>
> >>
> >>
> >> -----邮件原件-----
> >> 发件人: Julia Lawall [mailto:julia.lawall at lip6.fr]
> >> 发送时间: 2014年1月26日 19:19
> >> 收件人: 林嘉(程二 福州)
> >> 抄送: cocci at systeme.lip6.fr
> >> 主题: Re: [Cocci] how to write such matching case?
> >>
> >> On Sun, 26 Jan 2014, 林嘉(程二 福州) wrote:
> >>
> >> > In my project, it's required that if function A is called, and 
> >> > function B must be called following, just like this
> >> >
> >> > Foo(...)
> >> > {
> >> >    If ... {
> >> >        A(....);
> >> >        ...
> >> >        B(....);
> >> >    }
> >> > }
> >> >
> >> > Or
> >> >
> >> > Foo1(...)
> >> > {
> >> >         A(....);
> >> >         B(...);
> >> >  }
> >> >
> >> >
> >> > How to write a patch to find the missing case? Such as
> >> >
> >> > Foo(...)
> >> > {
> >> >    If ... {
> >> >        A(....);
> >> >        ...
> >> >    }
> >> > }
> >> >
> >> > Or
> >> >
> >> > Foo1(...)
> >> > {
> >> >        A(....);
> >> >        ...
> >> > }
> >>
> >> A(...)
> >> ... When != B(...)
> >>
> >> julia
> >>
> > _______________________________________________
> > Cocci mailing list
> > Cocci at systeme.lip6.fr
> > https://systeme.lip6.fr/mailman/listinfo/cocci
> 
> 
> 
> --
> Peter
> 


More information about the Cocci mailing list