All of lore.kernel.org
 help / color / mirror / Atom feed
* [Cocci] Finding usage of the statement "goto" with SmPL
@ 2015-12-09 13:50 SF Markus Elfring
  2015-12-09 14:01 ` Julia Lawall
  0 siblings, 1 reply; 3+ messages in thread
From: SF Markus Elfring @ 2015-12-09 13:50 UTC (permalink / raw)
  To: cocci

Hello,

I have tried another tiny SmPL script out.

@jumping@
identifier label;
@@
*goto label;


This test example works as expected.

elfring at Sonne:~/Projekte/Coccinelle/janitor> spatch.opt show_goto_usage1.cocci ~/Projekte/Linux/next-patched/drivers/block/zram/zram_drv.c
?
@@ -1424,7 +1400,6 @@ static int __init zram_init(void)
                ret = zram_add();
                mutex_unlock(&zram_index_mutex);
                if (ret < 0)
-                       goto out_error;
                num_devices--;
        }
 

Now I am trying also to generate other display formats for the corresponding data
with a SmPL approach like the following.

?
@contains_goto@
identifier label, work;
position g_pos, pos;
type return_type;
@@
 return_type work at pos(...)
 {
 ... when any
 goto label at g_pos;
 ... when any
 }

@script:python collection depends on contains_goto@
fun << contains_goto.work;
places << contains_goto.pos;
go_to << contains_goto.label;
jump_at << contains_goto.g_pos;
@@
print("collection: " + "fun=" + fun + " | go_to=" + go_to)
store_positions(fun, places, go_to, jump_at)
?


elfring@Sonne:~/Projekte/Coccinelle/janitor/jumping1> spatch.opt list_functions_with_goto1.cocci ~/Projekte/Linux/next-patched/drivers/block/zram/zram_drv.c
?
No result for this analysis!


Unfortunately, I get the impression that the SmPL rule does not get executed
because the base rule "contains_goto" might not produce the desired data.
How should this surprise be resolved?

Regards,
Markus

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

* [Cocci] Finding usage of the statement "goto" with SmPL
  2015-12-09 13:50 [Cocci] Finding usage of the statement "goto" with SmPL SF Markus Elfring
@ 2015-12-09 14:01 ` Julia Lawall
  2015-12-09 14:15   ` SF Markus Elfring
  0 siblings, 1 reply; 3+ messages in thread
From: Julia Lawall @ 2015-12-09 14:01 UTC (permalink / raw)
  To: cocci



On Wed, 9 Dec 2015, SF Markus Elfring wrote:

> Hello,
>
> I have tried another tiny SmPL script out.
>
> @jumping@
> identifier label;
> @@
> *goto label;
>
>
> This test example works as expected.
>
> elfring at Sonne:~/Projekte/Coccinelle/janitor> spatch.opt show_goto_usage1.cocci ~/Projekte/Linux/next-patched/drivers/block/zram/zram_drv.c
> ?
> @@ -1424,7 +1400,6 @@ static int __init zram_init(void)
>                 ret = zram_add();
>                 mutex_unlock(&zram_index_mutex);
>                 if (ret < 0)
> -                       goto out_error;
>                 num_devices--;
>         }
>
>
> Now I am trying also to generate other display formats for the corresponding data
> with a SmPL approach like the following.
>
> ?
> @contains_goto@
> identifier label, work;
> position g_pos, pos;
> type return_type;
> @@
>  return_type work at pos(...)
>  {
>  ... when any
>  goto label at g_pos;
>  ... when any
>  }
>
> @script:python collection depends on contains_goto@
> fun << contains_goto.work;
> places << contains_goto.pos;
> go_to << contains_goto.label;
> jump_at << contains_goto.g_pos;
> @@
> print("collection: " + "fun=" + fun + " | go_to=" + go_to)
> store_positions(fun, places, go_to, jump_at)
> ?
>
>
> elfring at Sonne:~/Projekte/Coccinelle/janitor/jumping1> spatch.opt list_functions_with_goto1.cocci ~/Projekte/Linux/next-patched/drivers/block/zram/zram_drv.c
> ?
> No result for this analysis!

It doesn't match anything because when you write a rule that has no *,
then it is considered that you want the pattern to match on every
execution path.  It is unlikely that the goto is on every execution path,
so you get nothing.  To solve the problem, just put exists in the initial
@@

If you don't care about the position of the function header of the
containing function, but could live with just the function name, you can
access it much more efficiently from a position variable on the goto, in
the field current_element.

julia

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

* [Cocci] Finding usage of the statement "goto" with SmPL
  2015-12-09 14:01 ` Julia Lawall
@ 2015-12-09 14:15   ` SF Markus Elfring
  0 siblings, 0 replies; 3+ messages in thread
From: SF Markus Elfring @ 2015-12-09 14:15 UTC (permalink / raw)
  To: cocci

> It doesn't match anything because when you write a rule that has no *,
> then it is considered that you want the pattern to match on every
> execution path.  It is unlikely that the goto is on every execution path,
> so you get nothing.

This is true.


> To solve the problem, just put exists in the initial @@

Thanks for your quick clarification.

I'm sorry that I overlooked this SmPL script setting somehow.
Now I get also the expected results for this SmPL approach.


function|"source file"|line|column|go_to|label_line|label_column
__zram_make_request|"/home/elfring/Projekte/Linux/next-patched/drivers/block/zram/zram_drv.c"|841|13|out|874|10
?
zram_rw_page|"/home/elfring/Projekte/Linux/next-patched/drivers/block/zram/zram_drv.c"|937|12|put_zram|952|8


> If you don't care about the position of the function header of the
> containing function, but could live with just the function name,

I reuse the information "line" and "column" from this metavariable intentionally.


> you can access it much more efficiently from a position variable on the goto,
> in the field current_element.

I will consider such fine-tuning for other source code analysis.

Regards,
Markus

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

end of thread, other threads:[~2015-12-09 14:15 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-12-09 13:50 [Cocci] Finding usage of the statement "goto" with SmPL SF Markus Elfring
2015-12-09 14:01 ` Julia Lawall
2015-12-09 14:15   ` SF Markus Elfring

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.