[Cocci] Finding function implementations that call only a single function.

Julia Lawall julia.lawall at lip6.fr
Sun Dec 7 10:31:45 CET 2014


OK, now the C file is manageable, if I drop the 20 lines of comments at 
the top of the file.

The following is also a completely understandable semantic patch:

> @single_function_call@
> identifier caller, input, work;
> type input_type, return_type;
> @@
> *return_type caller(input_type input)
>  {
> (
>   work(input);
> |
>   return work(input);
> )
>  }
> 
> @single_function_call_with_pointer@
> identifier caller, element, input, work;
> type input_type, return_type;
> @@
> *return_type caller(input_type * input)
>  {
> (
>   work(input->element);
> |
>   return work(input->element);
> )
>  }

So, now what is the problem with the following output?

> elfring at Sonne:~/Projekte/Coccinelle/Probe> spatch.opt -sp-file find_single_function_call1.cocci ast_ttm-excerpt1.c
> init_defs_builtins: /usr/local/share/coccinelle/standard.h
> HANDLING: ast_ttm-excerpt1.c
> diff = 
> --- ast_ttm-excerpt1.c
> +++ /tmp/cocci-output-19572-537bbf-ast_ttm-excerpt1.c
> @@ -25,24 +25,18 @@
>  /*
>   * Authors: Dave Airlie <airlied at redhat.com>
>   */
> -static int
> -ast_ttm_mem_global_init(struct drm_global_reference *ref)
>  {
>         return ttm_mem_global_init(ref->object);
>  }
>  
> -static void
> -ast_ttm_mem_global_release(struct drm_global_reference *ref)
>  {
>         ttm_mem_global_release(ref->object);
>  }
>  
> -static int ast_ttm_tt_populate(struct ttm_tt *ttm)
>  {
>         return ttm_pool_populate(ttm);
>  }
>  
> -static void ast_ttm_tt_unpopulate(struct ttm_tt *ttm)
>  {
>         ttm_pool_unpopulate(ttm);
>  }
> 
> 
> 
> One of my concerns here is the influence of the function return type
> on the SmPL evaluation speed so that more fine-tuning will be appropriate
> for the filter patterns.

Worrying about the speed of matching of a couple of tokens is completely 
pointless.  If you want to see that in practice, just use the --profile 
option and see what is the time with and without the matching you are 
concerned about.  Unless your pattern requires following a lot of 
different control-flow paths, eg due to sequences of conditionals, the C 
code parsing time will massively dominate the matching time.

julia


More information about the Cocci mailing list