cocci.inria.fr archive mirror
 help / color / mirror / Atom feed
* [Cocci] Removing the last return statement from a void function
@ 2021-03-18 18:26 Thomas Adam
  2021-03-18 19:24 ` Julia Lawall
  0 siblings, 1 reply; 4+ messages in thread
From: Thomas Adam @ 2021-03-18 18:26 UTC (permalink / raw)
  To: Coccinelle

Hello all,

I've another Coccinelle question I'm hoping you can help me with.  The
codebase I'm working on is old, and has some interesting styles which
by themselves probably don't cause any problems, but newer C compilers
are now starting to flag them.

In particular, there seems to be a pattern in this code base of using
explicit `return;` statements at the end of void functions.  Here's an
example:

static void broadcast_mini_icon(FvwmWindow *fw)
{
    if (!FMiniIconsSupported)
    {
        return;
    }
    if (fw->mini_pixmap_file && fw->mini_icon)
    {
        BroadcastFvwmPicture( M_MINI_ICON, FW_W(fw),
            FW_W_FRAME(fw), (unsigned long)fw,
            fw->mini_icon, fw->mini_pixmap_file);
    }
    return;
}

Here you can see the last return statement is not necessary.

I'm trying to make coccinelle recognise this and remove such cases.
Here's what I've tried:

@@
identifier f;
@@

void f(...) {
  <...
- return;
...>

}

... which sort of works, but proceeds to remove *all* `return;`
statements from void functions, rather than the last occurance in the
function.

Am I on the right track with this approach, or do I need to do
something more creative?

Thanks once more for your help.

Thomas
_______________________________________________
Cocci mailing list
Cocci@systeme.lip6.fr
https://systeme.lip6.fr/mailman/listinfo/cocci

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [Cocci] Removing the last return statement from a void function
  2021-03-18 18:26 [Cocci] Removing the last return statement from a void function Thomas Adam
@ 2021-03-18 19:24 ` Julia Lawall
  2021-03-19 20:40   ` Thomas Adam
  0 siblings, 1 reply; 4+ messages in thread
From: Julia Lawall @ 2021-03-18 19:24 UTC (permalink / raw)
  To: Thomas Adam; +Cc: Coccinelle



On Thu, 18 Mar 2021, Thomas Adam wrote:

> Hello all,
>
> I've another Coccinelle question I'm hoping you can help me with.  The
> codebase I'm working on is old, and has some interesting styles which
> by themselves probably don't cause any problems, but newer C compilers
> are now starting to flag them.
>
> In particular, there seems to be a pattern in this code base of using
> explicit `return;` statements at the end of void functions.  Here's an
> example:
>
> static void broadcast_mini_icon(FvwmWindow *fw)
> {
>     if (!FMiniIconsSupported)
>     {
>         return;
>     }
>     if (fw->mini_pixmap_file && fw->mini_icon)
>     {
>         BroadcastFvwmPicture( M_MINI_ICON, FW_W(fw),
>             FW_W_FRAME(fw), (unsigned long)fw,
>             fw->mini_icon, fw->mini_pixmap_file);
>     }
>     return;
> }
>
> Here you can see the last return statement is not necessary.
>
> I'm trying to make coccinelle recognise this and remove such cases.
> Here's what I've tried:
>
> @@
> identifier f;
> @@
>
> void f(...) {
>   <...
> - return;
> ...>
>
> }
>
> ... which sort of works, but proceeds to remove *all* `return;`
> statements from void functions, rather than the last occurance in the
> function.
>
> Am I on the right track with this approach, or do I need to do
> something more creative?

The ... in Coccinelle is based on control flow, so it is a bit hard to
find the return at the bottom of the function.  Actually, from
Coccinelle's point of view, all returns are at the bottom of the function,
because one leaves the function after a return.

You can try the following:

@r@
position p;
identifier f;
}

f(...) {
<...
{ .. return@p; }
...>
}

@@
position p != r.p;
@@

- return@p;

Basically the first rule collects the position of all returns that are
inside a { }, and then the second rule removes the others.

However there is an isomorphism that makes a pattern with { ... S } match
just S, for any S, which you don't want.  So you can make an empty file
called empty.iso, and then run the rule with the command-line argument
--iso-file empty.iso

julia
_______________________________________________
Cocci mailing list
Cocci@systeme.lip6.fr
https://systeme.lip6.fr/mailman/listinfo/cocci

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [Cocci] Removing the last return statement from a void function
  2021-03-18 19:24 ` Julia Lawall
@ 2021-03-19 20:40   ` Thomas Adam
  2021-03-19 21:10     ` Julia Lawall
  0 siblings, 1 reply; 4+ messages in thread
From: Thomas Adam @ 2021-03-19 20:40 UTC (permalink / raw)
  To: Julia Lawall; +Cc: Coccinelle

[-- Attachment #1: Type: text/plain, Size: 1720 bytes --]

On Thu, 18 Mar 2021 at 19:24, Julia Lawall <julia.lawall@inria.fr> wrote:

> The ... in Coccinelle is based on control flow, so it is a bit hard to
> find the return at the bottom of the function.  Actually, from
> Coccinelle's point of view, all returns are at the bottom of the function,
> because one leaves the function after a return.

Interesting, that helps me understand a little more about Coccinelle.  Thanks.

> You can try the following:
>
> @r@
> position p;
> identifier f;
> }
>
> f(...) {
> <...
> { .. return@p; }
> ...>
> }
>
> @@
> position p != r.p;
> @@
>
> - return@p;

So I tried this:

@r@
position p;
identifier f;
@@

f(...) {
<...
   { ... return@p; }
...>
}

@@
position p != r.p;
@@

- return@p;

Which I ran as:

spatch --in-place --debug --iso-file contrib/coccinelle/empty.iso \
    --sp-file ./contrib/coccinelle/remove-void-return.cocci --dir fvwm

With "--dir fvwm", I found that my CPU was being chewed at 100%, which I left
running overnight.  Some 8 hours later, spatch was still running.  Presumably,
Coccinelle is having an interesting time coordinating the positions?

Instead, I decided to loop over the .c files which "--dir fvwm" would have
done.  What I found was that for some files, spatch took a few seconds, and
produced no output, yet for some, spatch was still running without any result
known (so I killed it).

Indeed, I'm attaching a debug run of spatch to this email (cocci-debug) for
one file that definitely has functions where I would expect Coccinelle to have
matched a "return;" statement to be removed, but this wasn't the case.

Would you be able to suggest what I might have done wrong, or if there's any
additional debugging I can provide?

Thanks,
Thomas

[-- Attachment #2: cocci-debug --]
[-- Type: application/octet-stream, Size: 18953 bytes --]

init_defs_builtins: /usr/bin/../lib/coccinelle/standard.h
-----------------------------------------------------------------------
processing semantic patch file: ./contrib/coccinelle/remove-void-return.cocci
with isos from: contrib/coccinelle/empty.iso
-----------------------------------------------------------------------
@r@
position p;
identifier f;
@@

f(...) {
<...
   { ... return@p; }
...>
}

@@
position p != r.p;
@@

- return@p;

HANDLING: fvwm/add_window.c
-----------------------------------------------------------------------
let's go
-----------------------------------------------------------------------
-----------------------------------------------------------------------
(ONCE) ast_to_flow: filter a directive
-----------------------------------------------------------------------
r = 
-----------------------------------------------------------------------
dependencies for rule r satisfied:
binding in = []
binding relevant in = []
     (ONCE) USING optional_storage builtin isomorphism
     transformation info is empty
     binding out = [r.p --> poss[(fvwm/add_window.c,delete_client_context,((115,0),(130,1)),(129,1),(129,7))]]
     transformation info is empty
     binding out = [r.p --> poss[(fvwm/add_window.c,CaptureOneWindow,((142,0),(243,1)),(155,2),(155,8)), (fvwm/add_window.c,CaptureOneWindow,((142,0),(243,1)),(164,2),(164,8)), (fvwm/add_window.c,CaptureOneWindow,((142,0),(243,1)),(177,2),(177,8)), (fvwm/add_window.c,CaptureOneWindow,((142,0),(243,1)),(242,1),(242,7))]]
     transformation info is empty
     binding out = [r.p --> poss[(fvwm/add_window.c,hide_screen,((246,0),(331,1)),(268,2),(268,8)), (fvwm/add_window.c,hide_screen,((246,0),(331,1)),(330,1),(330,7))]]
     transformation info is empty
     binding out = []
     transformation info is empty
     binding out = [r.p --> poss[(fvwm/add_window.c,setup_window_structure,((383,0),(463,1)),(462,1),(462,7))]]
     transformation info is empty
     binding out = [r.p --> poss[(fvwm/add_window.c,setup_name_count,((465,0),(536,1)),(535,1),(535,7))]]
     transformation info is empty
     binding out = []
     transformation info is empty
     binding out = [r.p --> poss[(fvwm/add_window.c,setup_class_and_resource,((680,0),(698,1)),(697,1),(697,7))]]
     transformation info is empty
     binding out = [r.p --> poss[(fvwm/add_window.c,setup_window_attr,((700,0),(717,1)),(716,1),(716,7))]]
     transformation info is empty
     binding out = [r.p --> poss[(fvwm/add_window.c,destroy_window_font,((719,0),(734,1)),(733,1),(733,7))]]
     transformation info is empty
     binding out = [r.p --> poss[(fvwm/add_window.c,destroy_icon_font,((736,0),(749,1)),(748,1),(748,7))]]
     transformation info is empty
     binding out = [r.p --> poss[(fvwm/add_window.c,adjust_fvwm_internal_windows,((751,0),(779,1)),(778,1),(778,7))]]
     transformation info is empty
     binding out = [r.p --> poss[(fvwm/add_window.c,broadcast_mini_icon,((781,0),(796,1)),(785,2),(785,8)), (fvwm/add_window.c,broadcast_mini_icon,((781,0),(796,1)),(795,1),(795,7))]]
     transformation info is empty
     binding out = [r.p --> poss[(fvwm/add_window.c,setup_mini_icon,((798,0),(826,1)),(804,2),(804,8)), (fvwm/add_window.c,setup_mini_icon,((798,0),(826,1)),(825,1),(825,7))]]
     transformation info is empty
     binding out = [r.p --> poss[(fvwm/add_window.c,setup_icon_size_limits,((832,0),(852,1)),(851,1),(851,7))]]
     transformation info is empty
     binding out = [r.p --> poss[(fvwm/add_window.c,setup_icon_background_parameters,((854,0),(875,1)),(874,1),(874,7))]]
     transformation info is empty
     binding out = [r.p --> poss[(fvwm/add_window.c,setup_icon_title_parameters,((877,0),(889,1)),(888,1),(888,7))]]
     transformation info is empty
     binding out = [r.p --> poss[(fvwm/add_window.c,setup_numeric_vals,((891,0),(922,1)),(921,1),(921,7))]]
     transformation info is empty
     binding out = [r.p --> poss[(fvwm/add_window.c,setup_frame_window,((924,0),(968,1)),(967,1),(967,7))]]
     transformation info is empty
     binding out = [r.p --> poss[(fvwm/add_window.c,setup_title_window,((970,0),(983,1)),(982,1),(982,7))]]
     transformation info is empty
     binding out = [r.p --> poss[(fvwm/add_window.c,destroy_title_window,((985,0),(997,1)),(996,1),(996,7))]]
     transformation info is empty
     binding out = [r.p --> poss[(fvwm/add_window.c,change_title_window,((999,0),(1012,1)),(1011,1),(1011,7))]]
     transformation info is empty
     binding out = [r.p --> poss[(fvwm/add_window.c,setup_button_windows,((1014,0),(1057,1)),(1056,1),(1056,7))]]
     transformation info is empty
     binding out = [r.p --> poss[(fvwm/add_window.c,destroy_button_windows,((1059,0),(1084,1)),(1083,1),(1083,7))]]
     transformation info is empty
     binding out = [r.p --> poss[(fvwm/add_window.c,change_button_windows,((1086,0),(1101,1)),(1100,1),(1100,7))]]
     transformation info is empty
     binding out = [r.p --> poss[(fvwm/add_window.c,setup_parent_window,((1103,0),(1131,1)),(1130,1),(1130,7))]]
     transformation info is empty
     binding out = [r.p --> poss[(fvwm/add_window.c,setup_resize_handle_cursors,((1133,0),(1163,1)),(1141,2),(1141,8)), (fvwm/add_window.c,setup_resize_handle_cursors,((1133,0),(1163,1)),(1162,1),(1162,7))]]
     transformation info is empty
     binding out = [r.p --> poss[(fvwm/add_window.c,setup_resize_handle_windows,((1165,0),(1213,1)),(1185,2),(1185,8)), (fvwm/add_window.c,setup_resize_handle_windows,((1165,0),(1213,1)),(1212,1),(1212,7))]]
     transformation info is empty
     binding out = [r.p --> poss[(fvwm/add_window.c,destroy_resize_handle_windows,((1215,0),(1235,1)),(1234,1),(1234,7))]]
     transformation info is empty
     binding out = [r.p --> poss[(fvwm/add_window.c,change_resize_handle_windows,((1237,0),(1253,1)),(1252,1),(1252,7))]]
     transformation info is empty
     binding out = [r.p --> poss[(fvwm/add_window.c,setup_frame_stacking,((1255,0),(1321,1)),(1320,1),(1320,7))]]
     transformation info is empty
     binding out = [r.p --> poss[(fvwm/add_window.c,get_default_window_attributes,((1323,0),(1338,1)),(1337,1),(1337,7))]]
     transformation info is empty
     binding out = [r.p --> poss[(fvwm/add_window.c,setup_auxiliary_windows,((1340,0),(1363,1)),(1362,1),(1362,7))]]
     transformation info is empty
     binding out = [r.p --> poss[(fvwm/add_window.c,destroy_auxiliary_windows,((1365,0),(1390,1)),(1389,1),(1389,7))]]
     transformation info is empty
     binding out = [r.p --> poss[(fvwm/add_window.c,broadcast_window_names,((1392,0),(1405,1)),(1405,0),(1405,1))]]
     transformation info is empty
     binding out = [r.p --> poss[(fvwm/add_window.c,setup_icon,((1407,0),(1486,1)),(1485,1),(1485,7))]]
     transformation info is empty
     binding out = [r.p --> poss[(fvwm/add_window.c,destroy_icon,((1488,0),(1542,1)),(1541,1),(1541,7))]]
     transformation info is empty
     binding out = [r.p --> poss[(fvwm/add_window.c,setup_icon_boxes,((1544,0),(1563,1)),(1562,1),(1562,7))]]
     transformation info is empty
     binding out = [r.p --> poss[(fvwm/add_window.c,destroy_icon_boxes,((1565,0),(1579,1)),(1578,1),(1578,7))]]
     transformation info is empty
     binding out = [r.p --> poss[(fvwm/add_window.c,setup_layer,((1581,0),(1605,1)),(1604,1),(1604,7))]]
     transformation info is empty
     binding out = [r.p --> poss[(fvwm/add_window.c,destroy_mini_icon,((1607,0),(1616,1)),(1615,1),(1615,7))]]
     transformation info is empty
     binding out = [r.p --> poss[(fvwm/add_window.c,setup_key_and_button_grabs,((1618,0),(1637,1)),(1636,1),(1636,7))]]
     transformation info is empty
     binding out = [r.p --> poss[(fvwm/add_window.c,__add_window_handle_x_resources,((1639,0),(1694,1)),(1693,1),(1693,7))]]
     transformation info is empty
     binding out = []
     transformation info is empty
     binding out = []
     transformation info is empty
     binding out = [r.p --> poss[(fvwm/add_window.c,update_window_names,((1841,0),(1861,1)),(1860,1),(1860,7))]]
     transformation info is empty
     binding out = [r.p --> poss[(fvwm/add_window.c,setup_window_name,((1863,0),(1873,1)),(1872,1),(1872,7))]]
     transformation info is empty
     binding out = [r.p --> poss[(fvwm/add_window.c,setup_wm_hints,((1875,0),(1881,1)),(1880,1),(1880,7))]]
     transformation info is empty
     binding out = [r.p --> poss[(fvwm/add_window.c,setup_title_geometry,((1883,0),(1905,1)),(1904,1),(1904,7))]]
     transformation info is empty
     binding out = [r.p --> poss[(fvwm/add_window.c,setup_window_font,((1907,0),(1938,1)),(1937,1),(1937,7))]]
     transformation info is empty
     binding out = [r.p --> poss[(fvwm/add_window.c,setup_icon_font,((1940,0),(1990,1)),(1953,2),(1953,8)), (fvwm/add_window.c,setup_icon_font,((1940,0),(1990,1)),(1989,1),(1989,7))]]
     transformation info is empty
     binding out = [r.p --> poss[(fvwm/add_window.c,setup_style_and_decor,((1992,0),(2082,1)),(2081,1),(2081,7))]]
     transformation info is empty
     binding out = [r.p --> poss[(fvwm/add_window.c,change_icon_boxes,((2084,0),(2090,1)),(2089,1),(2089,7))]]
     transformation info is empty
     binding out = [r.p --> poss[(fvwm/add_window.c,setup_frame_size_limits,((2092,0),(2116,1)),(2115,1),(2115,7))]]
     transformation info is empty
     binding out = [r.p --> poss[(fvwm/add_window.c,setup_placement_penalty,((2118,0),(2138,1)),(2137,1),(2137,7))]]
     transformation info is empty
     binding out = [r.p --> poss[(fvwm/add_window.c,setup_frame_attributes,((2140,0),(2174,1)),(2173,1),(2173,7))]]
     transformation info is empty
     binding out = [r.p --> poss[(fvwm/add_window.c,change_auxiliary_windows,((2176,0),(2189,1)),(2188,1),(2188,7))]]
     transformation info is empty
     binding out = [r.p --> poss[(fvwm/add_window.c,increase_icon_hint_count,((2191,0),(2213,1)),(2212,1),(2212,7))]]
     transformation info is empty
     binding out = [r.p --> poss[(fvwm/add_window.c,change_icon,((2215,0),(2221,1)),(2220,1),(2220,7))]]
     transformation info is empty
     binding out = [r.p --> poss[(fvwm/add_window.c,change_mini_icon,((2223,0),(2239,1)),(2238,1),(2238,7))]]
     transformation info is empty
     binding out = [r.p --> poss[(fvwm/add_window.c,setup_focus_policy,((2241,0),(2246,1)),(2245,1),(2245,7))]]
     transformation info is empty
     binding out = []
     transformation info is empty
     binding out = []
     transformation info is empty
     binding out = []
     transformation info is empty
     binding out = [r.p --> poss[(fvwm/add_window.c,FetchWmProtocols,((2825,0),(2890,1)),(2836,2),(2836,8)), (fvwm/add_window.c,FetchWmProtocols,((2825,0),(2890,1)),(2889,1),(2889,7))]]
     transformation info is empty
     binding out = [r.p --> poss[(fvwm/add_window.c,GetWindowSizeHintsWithCheck,((2892,0),(3266,1)),(3265,1),(3265,7))]]
     transformation info is empty
     binding out = [r.p --> poss[(fvwm/add_window.c,GetWindowSizeHints,((3268,0),(3271,1)),(3271,0),(3271,1))]]
     transformation info is empty
     binding out = [r.p --> poss[(fvwm/add_window.c,free_window_names,((3278,0),(3332,1)),(3282,2),(3282,8)), (fvwm/add_window.c,free_window_names,((3278,0),(3332,1)),(3331,1),(3331,7))]]
     transformation info is empty
     binding out = [r.p --> poss[(fvwm/add_window.c,destroy_window,((3341,0),(3528,1)),(3348,2),(3348,8)), (fvwm/add_window.c,destroy_window,((3341,0),(3528,1)),(3400,3),(3400,9)), (fvwm/add_window.c,destroy_window,((3341,0),(3528,1)),(3435,2),(3435,8)), (fvwm/add_window.c,destroy_window,((3341,0),(3528,1)),(3527,1),(3527,7))]]
     transformation info is empty
     binding out = [r.p --> poss[(fvwm/add_window.c,RestoreWithdrawnLocation,((3539,0),(3651,1)),(3552,2),(3552,8)), (fvwm/add_window.c,RestoreWithdrawnLocation,((3539,0),(3651,1)),(3650,1),(3650,7))]]
     transformation info is empty
     binding out = [r.p --> poss[(fvwm/add_window.c,Reborder,((3660,0),(3691,1)),(3690,1),(3690,7))]]
     transformation info is empty
     binding out = [r.p --> poss[(fvwm/add_window.c,CaptureAllWindows,((3693,0),(3817,1)),(3705,2),(3705,8)), (fvwm/add_window.c,CaptureAllWindows,((3693,0),(3817,1)),(3816,1),(3816,7))]]
-----------------------------------------------------------------------
rule starting on line 12 = 
-----------------------------------------------------------------------
dependencies for rule rule starting on line 12 satisfied:
binding in = []
binding relevant in = [r.p --> poss[(fvwm/add_window.c,CaptureAllWindows,((3693,0),(3817,1)),(3705,2),(3705,8)), (fvwm/add_window.c,CaptureAllWindows,((3693,0),(3817,1)),(3816,1),(3816,7)), (fvwm/add_window.c,CaptureOneWindow,((142,0),(243,1)),(155,2),(155,8)), (fvwm/add_window.c,CaptureOneWindow,((142,0),(243,1)),(164,2),(164,8)), (fvwm/add_window.c,CaptureOneWindow,((142,0),(243,1)),(177,2),(177,8)), (fvwm/add_window.c,CaptureOneWindow,((142,0),(243,1)),(242,1),(242,7)), (fvwm/add_window.c,FetchWmProtocols,((2825,0),(2890,1)),(2836,2),(2836,8)), (fvwm/add_window.c,FetchWmProtocols,((2825,0),(2890,1)),(2889,1),(2889,7)), (fvwm/add_window.c,GetWindowSizeHints,((3268,0),(3271,1)),(3271,0),(3271,1)), (fvwm/add_window.c,GetWindowSizeHintsWithCheck,((2892,0),(3266,1)),(3265,1),(3265,7)), (fvwm/add_window.c,Reborder,((3660,0),(3691,1)),(3690,1),(3690,7)), (fvwm/add_window.c,RestoreWithdrawnLocation,((3539,0),(3651,1)),(3552,2),(3552,8)), (fvwm/add_window.c,RestoreWithdrawnLocation,((3539,0),(3651,1)),(3650,1),(3650,7)), (fvwm/add_window.c,__add_window_handle_x_resources,((1639,0),(1694,1)),(1693,1),(1693,7)), (fvwm/add_window.c,adjust_fvwm_internal_windows,((751,0),(779,1)),(778,1),(778,7)), (fvwm/add_window.c,broadcast_mini_icon,((781,0),(796,1)),(785,2),(785,8)), (fvwm/add_window.c,broadcast_mini_icon,((781,0),(796,1)),(795,1),(795,7)), (fvwm/add_window.c,broadcast_window_names,((1392,0),(1405,1)),(1405,0),(1405,1)), (fvwm/add_window.c,change_auxiliary_windows,((2176,0),(2189,1)),(2188,1),(2188,7)), (fvwm/add_window.c,change_button_windows,((1086,0),(1101,1)),(1100,1),(1100,7)), (fvwm/add_window.c,change_icon,((2215,0),(2221,1)),(2220,1),(2220,7)), (fvwm/add_window.c,change_icon_boxes,((2084,0),(2090,1)),(2089,1),(2089,7)), (fvwm/add_window.c,change_mini_icon,((2223,0),(2239,1)),(2238,1),(2238,7)), (fvwm/add_window.c,change_resize_handle_windows,((1237,0),(1253,1)),(1252,1),(1252,7)), (fvwm/add_window.c,change_title_window,((999,0),(1012,1)),(1011,1),(1011,7)), (fvwm/add_window.c,delete_client_context,((115,0),(130,1)),(129,1),(129,7)), (fvwm/add_window.c,destroy_auxiliary_windows,((1365,0),(1390,1)),(1389,1),(1389,7)), (fvwm/add_window.c,destroy_button_windows,((1059,0),(1084,1)),(1083,1),(1083,7)), (fvwm/add_window.c,destroy_icon,((1488,0),(1542,1)),(1541,1),(1541,7)), (fvwm/add_window.c,destroy_icon_boxes,((1565,0),(1579,1)),(1578,1),(1578,7)), (fvwm/add_window.c,destroy_icon_font,((736,0),(749,1)),(748,1),(748,7)), (fvwm/add_window.c,destroy_mini_icon,((1607,0),(1616,1)),(1615,1),(1615,7)), (fvwm/add_window.c,destroy_resize_handle_windows,((1215,0),(1235,1)),(1234,1),(1234,7)), (fvwm/add_window.c,destroy_title_window,((985,0),(997,1)),(996,1),(996,7)), (fvwm/add_window.c,destroy_window,((3341,0),(3528,1)),(3348,2),(3348,8)), (fvwm/add_window.c,destroy_window,((3341,0),(3528,1)),(3400,3),(3400,9)), (fvwm/add_window.c,destroy_window,((3341,0),(3528,1)),(3435,2),(3435,8)), (fvwm/add_window.c,destroy_window,((3341,0),(3528,1)),(3527,1),(3527,7)), (fvwm/add_window.c,destroy_window_font,((719,0),(734,1)),(733,1),(733,7)), (fvwm/add_window.c,free_window_names,((3278,0),(3332,1)),(3282,2),(3282,8)), (fvwm/add_window.c,free_window_names,((3278,0),(3332,1)),(3331,1),(3331,7)), (fvwm/add_window.c,get_default_window_attributes,((1323,0),(1338,1)),(1337,1),(1337,7)), (fvwm/add_window.c,hide_screen,((246,0),(331,1)),(268,2),(268,8)), (fvwm/add_window.c,hide_screen,((246,0),(331,1)),(330,1),(330,7)), (fvwm/add_window.c,increase_icon_hint_count,((2191,0),(2213,1)),(2212,1),(2212,7)), (fvwm/add_window.c,setup_auxiliary_windows,((1340,0),(1363,1)),(1362,1),(1362,7)), (fvwm/add_window.c,setup_button_windows,((1014,0),(1057,1)),(1056,1),(1056,7)), (fvwm/add_window.c,setup_class_and_resource,((680,0),(698,1)),(697,1),(697,7)), (fvwm/add_window.c,setup_focus_policy,((2241,0),(2246,1)),(2245,1),(2245,7)), (fvwm/add_window.c,setup_frame_attributes,((2140,0),(2174,1)),(2173,1),(2173,7)), (fvwm/add_window.c,setup_frame_size_limits,((2092,0),(2116,1)),(2115,1),(2115,7)), (fvwm/add_window.c,setup_frame_stacking,((1255,0),(1321,1)),(1320,1),(1320,7)), (fvwm/add_window.c,setup_frame_window,((924,0),(968,1)),(967,1),(967,7)), (fvwm/add_window.c,setup_icon,((1407,0),(1486,1)),(1485,1),(1485,7)), (fvwm/add_window.c,setup_icon_background_parameters,((854,0),(875,1)),(874,1),(874,7)), (fvwm/add_window.c,setup_icon_boxes,((1544,0),(1563,1)),(1562,1),(1562,7)), (fvwm/add_window.c,setup_icon_font,((1940,0),(1990,1)),(1953,2),(1953,8)), (fvwm/add_window.c,setup_icon_font,((1940,0),(1990,1)),(1989,1),(1989,7)), (fvwm/add_window.c,setup_icon_size_limits,((832,0),(852,1)),(851,1),(851,7)), (fvwm/add_window.c,setup_icon_title_parameters,((877,0),(889,1)),(888,1),(888,7)), (fvwm/add_window.c,setup_key_and_button_grabs,((1618,0),(1637,1)),(1636,1),(1636,7)), (fvwm/add_window.c,setup_layer,((1581,0),(1605,1)),(1604,1),(1604,7)), (fvwm/add_window.c,setup_mini_icon,((798,0),(826,1)),(804,2),(804,8)), (fvwm/add_window.c,setup_mini_icon,((798,0),(826,1)),(825,1),(825,7)), (fvwm/add_window.c,setup_name_count,((465,0),(536,1)),(535,1),(535,7)), (fvwm/add_window.c,setup_numeric_vals,((891,0),(922,1)),(921,1),(921,7)), (fvwm/add_window.c,setup_parent_window,((1103,0),(1131,1)),(1130,1),(1130,7)), (fvwm/add_window.c,setup_placement_penalty,((2118,0),(2138,1)),(2137,1),(2137,7)), (fvwm/add_window.c,setup_resize_handle_cursors,((1133,0),(1163,1)),(1141,2),(1141,8)), (fvwm/add_window.c,setup_resize_handle_cursors,((1133,0),(1163,1)),(1162,1),(1162,7)), (fvwm/add_window.c,setup_resize_handle_windows,((1165,0),(1213,1)),(1185,2),(1185,8)), (fvwm/add_window.c,setup_resize_handle_windows,((1165,0),(1213,1)),(1212,1),(1212,7)), (fvwm/add_window.c,setup_style_and_decor,((1992,0),(2082,1)),(2081,1),(2081,7)), (fvwm/add_window.c,setup_title_geometry,((1883,0),(1905,1)),(1904,1),(1904,7)), (fvwm/add_window.c,setup_title_window,((970,0),(983,1)),(982,1),(982,7)), (fvwm/add_window.c,setup_window_attr,((700,0),(717,1)),(716,1),(716,7)), (fvwm/add_window.c,setup_window_font,((1907,0),(1938,1)),(1937,1),(1937,7)), (fvwm/add_window.c,setup_window_name,((1863,0),(1873,1)),(1872,1),(1872,7)), (fvwm/add_window.c,setup_window_structure,((383,0),(463,1)),(462,1),(462,7)), (fvwm/add_window.c,setup_wm_hints,((1875,0),(1881,1)),(1880,1),(1880,7)), (fvwm/add_window.c,update_window_names,((1841,0),(1861,1)),(1860,1),(1860,7))]]
-----------------------------------------------------------------------
Finished
-----------------------------------------------------------------------
Check duplication for 1 files

[-- Attachment #3: Type: text/plain, Size: 136 bytes --]

_______________________________________________
Cocci mailing list
Cocci@systeme.lip6.fr
https://systeme.lip6.fr/mailman/listinfo/cocci

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [Cocci] Removing the last return statement from a void function
  2021-03-19 20:40   ` Thomas Adam
@ 2021-03-19 21:10     ` Julia Lawall
  0 siblings, 0 replies; 4+ messages in thread
From: Julia Lawall @ 2021-03-19 21:10 UTC (permalink / raw)
  To: Thomas Adam; +Cc: Coccinelle



On Fri, 19 Mar 2021, Thomas Adam wrote:

> On Thu, 18 Mar 2021 at 19:24, Julia Lawall <julia.lawall@inria.fr> wrote:
>
> > The ... in Coccinelle is based on control flow, so it is a bit hard to
> > find the return at the bottom of the function.  Actually, from
> > Coccinelle's point of view, all returns are at the bottom of the function,
> > because one leaves the function after a return.
>
> Interesting, that helps me understand a little more about Coccinelle.  Thanks.
>
> > You can try the following:
> >
> > @r@
> > position p;
> > identifier f;
> > }
> >
> > f(...) {
> > <...
> > { .. return@p; }
> > ...>
> > }
> >
> > @@
> > position p != r.p;
> > @@
> >
> > - return@p;
>
> So I tried this:
>
> @r@
> position p;
> identifier f;
> @@
>
> f(...) {
> <...
>    { ... return@p; }
> ...>
> }
>
> @@
> position p != r.p;
> @@
>
> - return@p;
>
> Which I ran as:
>
> spatch --in-place --debug --iso-file contrib/coccinelle/empty.iso \
>     --sp-file ./contrib/coccinelle/remove-void-return.cocci --dir fvwm
>
> With "--dir fvwm", I found that my CPU was being chewed at 100%, which I left
> running overnight.  Some 8 hours later, spatch was still running.  Presumably,
> Coccinelle is having an interesting time coordinating the positions?
>
> Instead, I decided to loop over the .c files which "--dir fvwm" would have
> done.  What I found was that for some files, spatch took a few seconds, and
> produced no output, yet for some, spatch was still running without any result
> known (so I killed it).
>
> Indeed, I'm attaching a debug run of spatch to this email (cocci-debug) for
> one file that definitely has functions where I would expect Coccinelle to have
> matched a "return;" statement to be removed, but this wasn't the case.
>
> Would you be able to suggest what I might have done wrong, or if there's any
> additional debugging I can provide?

If Coccinelle gets stuck on one part of a file, it won't move on to the
next part.  So the fact that the something should have been done in the
file is not really helpful.

You can use the argument --show-trying to see what function it is working
on at the moment.

You can use --timeout N to limit the treatment of a given file to N
seconds.

It may help to replace @r@ by @r exists@.

julia
_______________________________________________
Cocci mailing list
Cocci@systeme.lip6.fr
https://systeme.lip6.fr/mailman/listinfo/cocci

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2021-03-19 21:10 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-18 18:26 [Cocci] Removing the last return statement from a void function Thomas Adam
2021-03-18 19:24 ` Julia Lawall
2021-03-19 20:40   ` Thomas Adam
2021-03-19 21:10     ` Julia Lawall

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).