All of lore.kernel.org
 help / color / mirror / Atom feed
* [Cocci] Comparing statement lists with SmPL
@ 2017-08-15 17:26 SF Markus Elfring
  2017-08-15 17:33 ` Julia Lawall
  0 siblings, 1 reply; 33+ messages in thread
From: SF Markus Elfring @ 2017-08-15 17:26 UTC (permalink / raw)
  To: cocci

Hello,

The Coccinelle software supports metavariables with the type ?statement list?.
Can statement lists be compared if they refer to the same source code structures?
Is this programming interface usable to determine if any code could be combined
to some degree?

Regards,
Markus

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

* [Cocci] Comparing statement lists with SmPL
  2017-08-15 17:26 [Cocci] Comparing statement lists with SmPL SF Markus Elfring
@ 2017-08-15 17:33 ` Julia Lawall
  2017-08-15 19:04   ` SF Markus Elfring
  2017-08-16  6:10   ` SF Markus Elfring
  0 siblings, 2 replies; 33+ messages in thread
From: Julia Lawall @ 2017-08-15 17:33 UTC (permalink / raw)
  To: cocci



On Tue, 15 Aug 2017, SF Markus Elfring wrote:

> Hello,
>
> The Coccinelle software supports metavariables with the type ?statement list?.
> Can statement lists be compared if they refer to the same source code structures?
> Is this programming interface usable to determine if any code could be combined
> to some degree?

I don't really understand the questions.  Statement list metavariables can
be used once they are bound like any other metavariables.  However they
can only be bound to the complete sequence of statements in a block.  So

@@
statement list sl;
@@
if (x) {
  sl
}

is ok, but

@@
statement list sl;
@@
if (x) {
  one();
  sl
  two();
}

is not.

julia

>
> Regards,
> Markus
> _______________________________________________
> Cocci mailing list
> Cocci at systeme.lip6.fr
> https://systeme.lip6.fr/mailman/listinfo/cocci
>

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

* [Cocci] Comparing statement lists with SmPL
  2017-08-15 17:33 ` Julia Lawall
@ 2017-08-15 19:04   ` SF Markus Elfring
  2017-08-15 19:09     ` Julia Lawall
  2017-08-15 20:00     ` SF Markus Elfring
  2017-08-16  6:10   ` SF Markus Elfring
  1 sibling, 2 replies; 33+ messages in thread
From: SF Markus Elfring @ 2017-08-15 19:04 UTC (permalink / raw)
  To: cocci

>> Is this programming interface usable to determine if any code could be combined
>> to some degree?
> 
> I don't really understand the questions.

I try again to describe the use case I became interested in a bit more.


> Statement list metavariables can be used once they are bound like any other metavariables.

Can it be that they will need any special computing power occasionally?


I have tried the following small SmPL script out.

@duplicated_code@
identifier work;
statement list sl;
type T;
@@
 T work(...)
 {
 ... when any
*if ((...) < 0) {
*   sl
*}
 ...
*if ((...) < 0) {
*   sl
*}
 ...
 }


The source code analysis results look promising by this command.

elfring@Sonne:~/Projekte/Linux/next-patched> git checkout next-20170803 && spatch.opt ~/Projekte/Coccinelle/janitor/show_same_statements1.cocci sound/pci/rme9652/hdsp.c
?
@@ -793,11 +793,6 @@ static int hdsp_get_iobox_version (struc
?
@@ -5382,19 +5372,11 @@ static int snd_hdsp_probe(struct pci_dev
?


How should such update candidates be transformed further?


> However they can only be bound to the complete sequence of statements in a block.  So
> 
> @@
> statement list sl;
> @@
> if (x) {
>   sl
> }
> 
> is ok, but
> 
> @@
> statement list sl;
> @@
> if (x) {
>   one();
>   sl
>   two();
> }
> 
> is not.

Thanks for your example.

* I do not like the mentioned software restriction at the moment.

* How can be determined how many code is equivalent between two statement list variables?

Regards,
Markus

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

* [Cocci] Comparing statement lists with SmPL
  2017-08-15 19:04   ` SF Markus Elfring
@ 2017-08-15 19:09     ` Julia Lawall
  2017-08-15 19:14       ` SF Markus Elfring
  2017-08-15 20:00     ` SF Markus Elfring
  1 sibling, 1 reply; 33+ messages in thread
From: Julia Lawall @ 2017-08-15 19:09 UTC (permalink / raw)
  To: cocci

> * How can be determined how many code is equivalent between two statement list variables?

I guess you can make special cases, for one statement, two statements,
etc.

julia

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

* [Cocci] Comparing statement lists with SmPL
  2017-08-15 19:09     ` Julia Lawall
@ 2017-08-15 19:14       ` SF Markus Elfring
  0 siblings, 0 replies; 33+ messages in thread
From: SF Markus Elfring @ 2017-08-15 19:14 UTC (permalink / raw)
  To: cocci

>> * How can be determined how many code is equivalent between two statement list variables?
> 
> I guess you can make special cases, for one statement, two statements, etc.

I guess that we would like to avoid such an approach for some use cases.
I hope that there are safer programming possibilities available.

Regards,
Markus

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

* [Cocci] Comparing statement lists with SmPL
  2017-08-15 19:04   ` SF Markus Elfring
  2017-08-15 19:09     ` Julia Lawall
@ 2017-08-15 20:00     ` SF Markus Elfring
  2017-08-15 20:09       ` Julia Lawall
  1 sibling, 1 reply; 33+ messages in thread
From: SF Markus Elfring @ 2017-08-15 20:00 UTC (permalink / raw)
  To: cocci

> The source code analysis results look promising by this command.

I have just noticed that an other source file points details out for further
development considerations around the mentioned functionality from the
Coccinelle software.

elfring at Sonne:~/Projekte/Linux/next-patched> git checkout next-20170803 && spatch.opt ~/Projekte/Coccinelle/janitor/show_same_statements1.cocci sound/pci/rme9652/hdspm.c
?
     (ONCE) already tagged but only removed, so safe
diff = 
?
@@ -6497,9 +6497,6 @@ static int snd_hdspm_create_alsa_devices
 	i = 0;
 	while (i < hdspm->midiPorts) {
 		err = snd_hdspm_create_midi(card, hdspm, i);
-		if (err < 0) {
-			return err;
-		}
 		i++;
 	}
 
@@ -6955,10 +6952,6 @@ static int snd_hdspm_probe(struct pci_de
 	hdspm->pci = pci;
 
 	err = snd_hdspm_create(card, hdspm);
-	if (err < 0) {
-		snd_card_free(card);
-		return err;
-	}
 
 	if (hdspm->io_type != MADIface) {
 		snprintf(card->shortname, sizeof(card->shortname), "%s_%x",
?


Now I am looking for a way to express the constraint that the statement list
metavariable should match only source code with two statements at least.
Can the search for duplicated source code be improved by the means of the
semantic patch language?

Regards,
Markus

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

* [Cocci] Comparing statement lists with SmPL
  2017-08-15 20:00     ` SF Markus Elfring
@ 2017-08-15 20:09       ` Julia Lawall
  2017-08-15 20:15         ` SF Markus Elfring
                           ` (2 more replies)
  0 siblings, 3 replies; 33+ messages in thread
From: Julia Lawall @ 2017-08-15 20:09 UTC (permalink / raw)
  To: cocci



On Tue, 15 Aug 2017, SF Markus Elfring wrote:

> > The source code analysis results look promising by this command.
>
> I have just noticed that an other source file points details out for further
> development considerations around the mentioned functionality from the
> Coccinelle software.
>
> elfring at Sonne:~/Projekte/Linux/next-patched> git checkout next-20170803 && spatch.opt ~/Projekte/Coccinelle/janitor/show_same_statements1.cocci sound/pci/rme9652/hdspm.c
> ?
>      (ONCE) already tagged but only removed, so safe
> diff =
> ?
> @@ -6497,9 +6497,6 @@ static int snd_hdspm_create_alsa_devices
>  	i = 0;
>  	while (i < hdspm->midiPorts) {
>  		err = snd_hdspm_create_midi(card, hdspm, i);
> -		if (err < 0) {
> -			return err;
> -		}
>  		i++;
>  	}
>
> @@ -6955,10 +6952,6 @@ static int snd_hdspm_probe(struct pci_de
>  	hdspm->pci = pci;
>
>  	err = snd_hdspm_create(card, hdspm);
> -	if (err < 0) {
> -		snd_card_free(card);
> -		return err;
> -	}
>
>  	if (hdspm->io_type != MADIface) {
>  		snprintf(card->shortname, sizeof(card->shortname), "%s_%x",
> ?
>
>
> Now I am looking for a way to express the constraint that the statement list
> metavariable should match only source code with two statements at least.
> Can the search for duplicated source code be improved by the means of the
> semantic patch language?

For two statements at least you could do:

(
{
s1
s2
...
}
&
{
sl
}
)

julia

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

* [Cocci] Comparing statement lists with SmPL
  2017-08-15 20:09       ` Julia Lawall
@ 2017-08-15 20:15         ` SF Markus Elfring
  2017-08-16  6:48         ` SF Markus Elfring
  2017-08-16  7:35         ` SF Markus Elfring
  2 siblings, 0 replies; 33+ messages in thread
From: SF Markus Elfring @ 2017-08-15 20:15 UTC (permalink / raw)
  To: cocci

>> Now I am looking for a way to express the constraint that the statement list
>> metavariable should match only source code with two statements at least.
>> Can the search for duplicated source code be improved by the means of the
>> semantic patch language?
> 
> For two statements at least you could do:
> 
> (
> {
> s1
> s2
> ...
> }
> &
> {
> sl
> }
> )

Thanks for another example.


I admit that I am unused to such a variable combination with a SmPL conjunction.
Will this programming interface evolve any further?

Regards,
Markus

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

* [Cocci] Comparing statement lists with SmPL
  2017-08-15 17:33 ` Julia Lawall
  2017-08-15 19:04   ` SF Markus Elfring
@ 2017-08-16  6:10   ` SF Markus Elfring
  2017-08-16  6:26     ` Julia Lawall
  1 sibling, 1 reply; 33+ messages in thread
From: SF Markus Elfring @ 2017-08-16  6:10 UTC (permalink / raw)
  To: cocci

> However they can only be bound to the complete sequence of statements in a block.  So
> 
> @@
> statement list sl;
> @@
> if (x) {
>   sl
> }
> 
> is ok, but
> 
> @@
> statement list sl;
> @@
> if (x) {
>   one();
>   sl
>   two();
> }
> 
> is not.

How do you think about the usage of a similar SmPL specification?

@display@
statement list sl;
@@
 if (...)
 {
    header();
    { // Extra block
*   sl
    }
    footer();
 }

Regards,
Markus

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

* [Cocci] Comparing statement lists with SmPL
  2017-08-16  6:10   ` SF Markus Elfring
@ 2017-08-16  6:26     ` Julia Lawall
  2017-08-16  6:38       ` SF Markus Elfring
  0 siblings, 1 reply; 33+ messages in thread
From: Julia Lawall @ 2017-08-16  6:26 UTC (permalink / raw)
  To: cocci



On Wed, 16 Aug 2017, SF Markus Elfring wrote:

> > However they can only be bound to the complete sequence of statements in a block.  So
> >
> > @@
> > statement list sl;
> > @@
> > if (x) {
> >   sl
> > }
> >
> > is ok, but
> >
> > @@
> > statement list sl;
> > @@
> > if (x) {
> >   one();
> >   sl
> >   two();
> > }
> >
> > is not.
>
> How do you think about the usage of a similar SmPL specification?
>
> @display@
> statement list sl;
> @@
>  if (...)
>  {
>     header();
>     { // Extra block
> *   sl
>     }
>     footer();
>  }

It's fine,  A statement list just needs { } around it.

julia

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

* [Cocci] Comparing statement lists with SmPL
  2017-08-16  6:26     ` Julia Lawall
@ 2017-08-16  6:38       ` SF Markus Elfring
  0 siblings, 0 replies; 33+ messages in thread
From: SF Markus Elfring @ 2017-08-16  6:38 UTC (permalink / raw)
  To: cocci

> It's fine,  A statement list just needs { } around it.

How much does this aspect influence a source code search when relevant source files
do not contain extra curly brackets?

Regards,
Markus

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

* [Cocci] Comparing statement lists with SmPL
  2017-08-15 20:09       ` Julia Lawall
  2017-08-15 20:15         ` SF Markus Elfring
@ 2017-08-16  6:48         ` SF Markus Elfring
  2017-08-16  7:03           ` SF Markus Elfring
  2017-08-16  9:01           ` Julia Lawall
  2017-08-16  7:35         ` SF Markus Elfring
  2 siblings, 2 replies; 33+ messages in thread
From: SF Markus Elfring @ 2017-08-16  6:48 UTC (permalink / raw)
  To: cocci

>> Can the search for duplicated source code be improved by the means of the
>> semantic patch language?
> 
> For two statements at least you could do:
> 
> (
> {
> s1
> s2
> ...
> }
> &
> {
> sl
> }
> )

I constructed another SmPL script based on this suggestion as follows.

@duplicated_code@
identifier work;
statement s1, s2;
statement list sl;
type T;
@@
 T work(...)
 {
 ... when any
*if ((...) < 0) {
*   s1
*   s2
    ...
*}
&{
    sl
 }
 ...
*if ((...) < 0) {
*   s1
*   s2
    ...
*}
&{
    sl
 }
 ...
 }


Unfortunately, the software version ?1.0.6-00186-g0acd38ee? does not like this
SmPL specification.

elfring@Sonne:~/Projekte/Coccinelle/janitor> spatch.opt --parse-cocci show_same_statements2.cocci
?
minus: parse error: 
  File "show_same_statements2.cocci", line 15, column 0, charpos = 156
  around = '&',
  whole content = &{


How can my understanding become better also for the use of SmPL conjunctions?

Regards,
Markus

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

* [Cocci] Comparing statement lists with SmPL
  2017-08-16  6:48         ` SF Markus Elfring
@ 2017-08-16  7:03           ` SF Markus Elfring
  2017-08-16  9:20             ` Julia Lawall
  2017-08-16  9:01           ` Julia Lawall
  1 sibling, 1 reply; 33+ messages in thread
From: SF Markus Elfring @ 2017-08-16  7:03 UTC (permalink / raw)
  To: cocci

> Unfortunately, the software version ?1.0.6-00186-g0acd38ee? does not like this
> SmPL specification.

I overlooked to add parentheses in my evolving SmPL script.

@duplicated_code@
identifier work;
statement s1, s2;
statement list sl;
type T;
@@
 T work(...)
 {
 ... when any
(
*if ((...) < 0) {
*   s1
*   s2
    ...
*}
&{
    sl
 }
)
 ...
(
*if ((...) < 0) {
*   s1
*   s2
    ...
*}
&{
    sl
 }
)
 ...
 }


The following command does not show the expected source code analysis results at the moment.

elfring@Sonne:~/Projekte/Coccinelle/janitor> spatch.opt show_same_statements2.cocci ../Probe/hdsp-excerpt1.c


Is there any more clarification needed for the use of SmPL conjunctions?

Regards,
Markus

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

* [Cocci] Comparing statement lists with SmPL
  2017-08-15 20:09       ` Julia Lawall
  2017-08-15 20:15         ` SF Markus Elfring
  2017-08-16  6:48         ` SF Markus Elfring
@ 2017-08-16  7:35         ` SF Markus Elfring
  2017-08-17 17:54           ` SF Markus Elfring
  2 siblings, 1 reply; 33+ messages in thread
From: SF Markus Elfring @ 2017-08-16  7:35 UTC (permalink / raw)
  To: cocci

>> Can the search for duplicated source code be improved by the means of the
>> semantic patch language?
> 
> For two statements at least you could do:

An other SmPL script variant can work to some degree.

@duplicated_code@
identifier work;
statement s1, s2;
type T;
@@
 T work(...)
 {
 ... when any
*if ((...) < 0)
*{
*   s1
*   s2
    ...
*}
 ...
*if ((...) < 0)
*{
*   s1
*   s2
    ...
*}
 ...
 }


But matched statements will not be mapped to the discussed metavariable type
in this use case.
I am curious on how such an approach can be used for corresponding source
code transformations.

Regards,
Markus

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

* [Cocci] Comparing statement lists with SmPL
  2017-08-16  6:48         ` SF Markus Elfring
  2017-08-16  7:03           ` SF Markus Elfring
@ 2017-08-16  9:01           ` Julia Lawall
  1 sibling, 0 replies; 33+ messages in thread
From: Julia Lawall @ 2017-08-16  9:01 UTC (permalink / raw)
  To: cocci



On Wed, 16 Aug 2017, SF Markus Elfring wrote:

> >> Can the search for duplicated source code be improved by the means of the
> >> semantic patch language?
> >
> > For two statements at least you could do:
> >
> > (
> > {
> > s1
> > s2
> > ...
> > }
> > &
> > {
> > sl
> > }
> > )
>
> I constructed another SmPL script based on this suggestion as follows.
>
> @duplicated_code@
> identifier work;
> statement s1, s2;
> statement list sl;
> type T;
> @@
>  T work(...)
>  {
>  ... when any
> *if ((...) < 0) {
> *   s1
> *   s2
>     ...
> *}
> &{
>     sl
>  }
>  ...
> *if ((...) < 0) {
> *   s1
> *   s2
>     ...
> *}
> &{
>     sl
>  }
>  ...
>  }
>
>
> Unfortunately, the software version ?1.0.6-00186-g0acd38ee? does not like this
> SmPL specification.

The syntax is exactly the same as that of a disjunction

(
&
)

There are no outer parentheses in column 0 in your specification.

julia


>
> elfring at Sonne:~/Projekte/Coccinelle/janitor> spatch.opt --parse-cocci show_same_statements2.cocci
> ?
> minus: parse error:
>   File "show_same_statements2.cocci", line 15, column 0, charpos = 156
>   around = '&',
>   whole content = &{
>
>
> How can my understanding become better also for the use of SmPL conjunctions?
>
> Regards,
> Markus
>

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

* [Cocci] Comparing statement lists with SmPL
  2017-08-16  7:03           ` SF Markus Elfring
@ 2017-08-16  9:20             ` Julia Lawall
  2017-08-16 10:42               ` SF Markus Elfring
  0 siblings, 1 reply; 33+ messages in thread
From: Julia Lawall @ 2017-08-16  9:20 UTC (permalink / raw)
  To: cocci



On Wed, 16 Aug 2017, SF Markus Elfring wrote:

> > Unfortunately, the software version ?1.0.6-00186-g0acd38ee? does not like this
> > SmPL specification.
>
> I overlooked to add parentheses in my evolving SmPL script.
>
> @duplicated_code@
> identifier work;
> statement s1, s2;
> statement list sl;
> type T;
> @@
>  T work(...)
>  {
>  ... when any
> (
> *if ((...) < 0) {
> *   s1
> *   s2
>     ...
> *}
> &{
>     sl
>  }
> )
>  ...
> (
> *if ((...) < 0) {
> *   s1
> *   s2
>     ...
> *}
> &{
>     sl
>  }
> )
>  ...
>  }
>
>
> The following command does not show the expected source code analysis results at the moment.
>
> elfring at Sonne:~/Projekte/Coccinelle/janitor> spatch.opt show_same_statements2.cocci ../Probe/hdsp-excerpt1.c

There is no way that I can understand the problme without having the .c
file.

Note that most of your ...s have no annotation.  So they cannot contain
what comes before or after.  I would suggest to put when any on all of the
...s here that are at statement level.

julia

>
>
> Is there any more clarification needed for the use of SmPL conjunctions?
>
> Regards,
> Markus
>

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

* [Cocci] Comparing statement lists with SmPL
  2017-08-16  9:20             ` Julia Lawall
@ 2017-08-16 10:42               ` SF Markus Elfring
  0 siblings, 0 replies; 33+ messages in thread
From: SF Markus Elfring @ 2017-08-16 10:42 UTC (permalink / raw)
  To: cocci

>> elfring at Sonne:~/Projekte/Coccinelle/janitor> spatch.opt show_same_statements2.cocci ../Probe/hdsp-excerpt1.c
> 
> There is no way that I can understand the problme without having the .c file.

I attached this one to a clarification request on the topic
?Improving exception handling a bit with SmPL? two days ago.

Corresponding change possibilities can also be seen in a patch with the subject
?ALSA: rme9652: Use common error handling code in two functions?
which I published on the same day.
https://patchwork.kernel.org/patch/9900021/
https://lkml.kernel.org/r/<fefeea4b-68a2-5b4c-2cfc-cb05383b5474@users.sourceforge.net>


> Note that most of your ...s have no annotation.  So they cannot contain
> what comes before or after.  I would suggest to put when any on all of the
> ...s here that are at statement level.

Thanks for this advice.

Regards,
Markus

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

* [Cocci] Comparing statement lists with SmPL
  2017-08-16  7:35         ` SF Markus Elfring
@ 2017-08-17 17:54           ` SF Markus Elfring
  2017-08-17 18:44             ` Julia Lawall
  0 siblings, 1 reply; 33+ messages in thread
From: SF Markus Elfring @ 2017-08-17 17:54 UTC (permalink / raw)
  To: cocci

>>> Can the search for duplicated source code be improved by the means of the
>>> semantic patch language?
>>
>> For two statements at least you could do:
> 
> An other SmPL script variant can work to some degree.

How do you think about the relevance of the SmPL construct ?<+... ...+>?
for this use case?


I tried my intermediate SmPL script variant a bit more.

Example:

elfring at Sonne:~/Projekte/Linux/next-patched> git checkout next-20170803 && spatch.opt ~/Projekte/Coccinelle/janitor/show_same_statements3.cocci fs/ubifs/lpt.c
?
@@ -1974,10 +1974,6 @@ again:
 		int ret, lnum = lprops->lnum;
 
 		ret = scan_cb(c, lprops, path[h].in_tree, data);
-		if (ret < 0) {
-			err = ret;
-			goto out;
-		}
 		if (ret & LPT_SCAN_ADD) {
 			/* Add all the nodes in path to the tree in memory */
 			for (h = 1; h < c->lpt_hght; h++) {


Now I wonder how this test result should fit to my source code search pattern.
I find also more results questionable for this Linux software module.
It seems that there are only two functions which would be an acceptable match.

Regards,
Markus

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

* [Cocci] Comparing statement lists with SmPL
  2017-08-17 17:54           ` SF Markus Elfring
@ 2017-08-17 18:44             ` Julia Lawall
  2017-08-17 19:26               ` SF Markus Elfring
  0 siblings, 1 reply; 33+ messages in thread
From: Julia Lawall @ 2017-08-17 18:44 UTC (permalink / raw)
  To: cocci



On Thu, 17 Aug 2017, SF Markus Elfring wrote:

> >>> Can the search for duplicated source code be improved by the means of the
> >>> semantic patch language?
> >>
> >> For two statements at least you could do:
> >
> > An other SmPL script variant can work to some degree.
>
> How do you think about the relevance of the SmPL construct ?<+... ...+>?
> for this use case?
>
>
> I tried my intermediate SmPL script variant a bit more.
>
> Example:
>
> elfring at Sonne:~/Projekte/Linux/next-patched> git checkout next-20170803 && spatch.opt ~/Projekte/Coccinelle/janitor/show_same_statements3.cocci fs/ubifs/lpt.c
> ?
> @@ -1974,10 +1974,6 @@ again:
>  		int ret, lnum = lprops->lnum;
>
>  		ret = scan_cb(c, lprops, path[h].in_tree, data);
> -		if (ret < 0) {
> -			err = ret;
> -			goto out;
> -		}
>  		if (ret & LPT_SCAN_ADD) {
>  			/* Add all the nodes in path to the tree in memory */
>  			for (h = 1; h < c->lpt_hght; h++) {
>
>
> Now I wonder how this test result should fit to my source code search pattern.

I guess there is a loop around this code, so it is reachable from itself.

julia

> I find also more results questionable for this Linux software module.
> It seems that there are only two functions which would be an acceptable match.
>
> Regards,
> Markus
>

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

* [Cocci] Comparing statement lists with SmPL
  2017-08-17 18:44             ` Julia Lawall
@ 2017-08-17 19:26               ` SF Markus Elfring
  2017-08-17 19:31                 ` Julia Lawall
  0 siblings, 1 reply; 33+ messages in thread
From: SF Markus Elfring @ 2017-08-17 19:26 UTC (permalink / raw)
  To: cocci

>> elfring at Sonne:~/Projekte/Linux/next-patched> git checkout next-20170803 && spatch.opt ~/Projekte/Coccinelle/janitor/show_same_statements3.cocci fs/ubifs/lpt.c
>> ?
>> @@ -1974,10 +1974,6 @@ again:
>>  		int ret, lnum = lprops->lnum;
>>
>>  		ret = scan_cb(c, lprops, path[h].in_tree, data);
>> -		if (ret < 0) {
>> -			err = ret;
>> -			goto out;
>> -		}
>>  		if (ret & LPT_SCAN_ADD) {
>>  			/* Add all the nodes in path to the tree in memory */
>>  			for (h = 1; h < c->lpt_hght; h++) {
>>
>>
>> Now I wonder how this test result should fit to my source code search pattern.
> 
> I guess there is a loop around this code, so it is reachable from itself.

* How can we achieve progress with such a bit of information?

* Should such false positives be avoided anyhow?

* Will answers to other questions become more helpful again?

* Are there further development challenges to consider for the safe identification
  of unique statements by metavariables?

Regards,
Markus

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

* [Cocci] Comparing statement lists with SmPL
  2017-08-17 19:26               ` SF Markus Elfring
@ 2017-08-17 19:31                 ` Julia Lawall
  2017-08-17 19:43                   ` SF Markus Elfring
  2017-08-22  9:19                   ` SF Markus Elfring
  0 siblings, 2 replies; 33+ messages in thread
From: Julia Lawall @ 2017-08-17 19:31 UTC (permalink / raw)
  To: cocci



On Thu, 17 Aug 2017, SF Markus Elfring wrote:

> >> elfring at Sonne:~/Projekte/Linux/next-patched> git checkout next-20170803 && spatch.opt ~/Projekte/Coccinelle/janitor/show_same_statements3.cocci fs/ubifs/lpt.c
> >> ?
> >> @@ -1974,10 +1974,6 @@ again:
> >>  		int ret, lnum = lprops->lnum;
> >>
> >>  		ret = scan_cb(c, lprops, path[h].in_tree, data);
> >> -		if (ret < 0) {
> >> -			err = ret;
> >> -			goto out;
> >> -		}
> >>  		if (ret & LPT_SCAN_ADD) {
> >>  			/* Add all the nodes in path to the tree in memory */
> >>  			for (h = 1; h < c->lpt_hght; h++) {
> >>
> >>
> >> Now I wonder how this test result should fit to my source code search pattern.
> >
> > I guess there is a loop around this code, so it is reachable from itself.
>
> * How can we achieve progress with such a bit of information?
>
> * Should such false positives be avoided anyhow?
>
> * Will answers to other questions become more helpful again?
>
> * Are there further development challenges to consider for the safe identification
>   of unique statements by metavariables?

If you want to ensure that two metavariables match things in different
places, then put a position variable on each match and use apython rule
afterwards to discard the occurrences that are both in the same position.

julia

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

* [Cocci] Comparing statement lists with SmPL
  2017-08-17 19:31                 ` Julia Lawall
@ 2017-08-17 19:43                   ` SF Markus Elfring
  2017-08-22  9:19                   ` SF Markus Elfring
  1 sibling, 0 replies; 33+ messages in thread
From: SF Markus Elfring @ 2017-08-17 19:43 UTC (permalink / raw)
  To: cocci

>> * Are there further development challenges to consider for the safe identification
>>   of unique statements by metavariables?
> 
> If you want to ensure that two metavariables match things in different
> places, then put a position variable on each match and use apython rule
> afterwards to discard the occurrences that are both in the same position.

I hoped for a more convenient search specification to reduce duplicate
source code a bit.

Regards,
Markus

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

* [Cocci] Comparing statement lists with SmPL
  2017-08-17 19:31                 ` Julia Lawall
  2017-08-17 19:43                   ` SF Markus Elfring
@ 2017-08-22  9:19                   ` SF Markus Elfring
  2017-08-22  9:28                     ` Julia Lawall
  2017-08-23 14:43                     ` SF Markus Elfring
  1 sibling, 2 replies; 33+ messages in thread
From: SF Markus Elfring @ 2017-08-22  9:19 UTC (permalink / raw)
  To: cocci

>> * Are there further development challenges to consider for the safe identification
>>   of unique statements by metavariables?
> 
> If you want to ensure that two metavariables match things
> in different places, then put a position variable on each match
> and use apython rule afterwards to discard the occurrences that
> are both in the same position.

I imagine that such an approach can only matter if there will be
several SmPL rules involved.


I have tried another variant out for a source code analysis.

@duplicated_code@
identifier work;
statement s1, s2;
type T;
@@
 T work(...)
 {
 <+...
*if ((...) < 0)
*{
    ...
*   s1
*   s2
*}
 ...+>
 <+...
*if ((...) < 0)
*{
    ...
*   s1
*   s2
*}
 ...+>
 }


elfring at Sonne:~/Projekte/Linux/next-patched> XX=$(date) && spatch.opt -timeout 34 -j 4 --chunksize 1 --sp-file ~/Projekte/Coccinelle/janitor/show_same_statements3.cocci --dir sound > ~/Projekte/Bau/Linux/scripts/Coccinelle/tuning1/next/20170803/same_statements3+.diff 2> ~/Projekte/Bau/Linux/scripts/Coccinelle/tuning1/next/20170803/same_statements3+-errors.txt; YY=$(date) && echo "$XX | $YY"
Di 22. Aug 10:24:47 CEST 2017 | Di 22. Aug 10:26:04 CEST 2017


Now I find that a test result like the following is worth for further
development considerations.

?
--- sound/usb/6fire/firmware.c
+++ /tmp/nothing/usb/6fire/firmware.c
@@ -246,14 +246,8 @@ static int usb6fire_fw_ezusb_upload(
 	while (usb6fire_fw_ihex_next_record(rec)) { /* write firmware */
 		ret = usb6fire_fw_ezusb_write(device, 0xa0, rec->address,
 				rec->data, rec->len);
-		if (ret < 0) {
 			kfree(rec);
 			release_firmware(fw);
-			dev_err(&intf->dev,
-				"unable to upload ezusb firmware %s: data urb.\n",
-				fwname);
-			return ret;
-		}
 	}
 
 	release_firmware(fw);
@@ -319,13 +313,8 @@ static int usb6fire_fw_fpga_upload(
 			buffer[i] = bitrev8((u8)*c);
 
 		ret = usb6fire_fw_fpga_write(device, buffer, i);
-		if (ret < 0) {
 			release_firmware(fw);
 			kfree(buffer);
-			dev_err(&intf->dev,
-				"unable to upload fpga firmware: fw urb.\n");
-			return ret;
-		}
 	}
 	release_firmware(fw);
 	kfree(buffer);
?


How would you like to treat variations in such log messages?

Regards,
Markus

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

* [Cocci] Comparing statement lists with SmPL
  2017-08-22  9:19                   ` SF Markus Elfring
@ 2017-08-22  9:28                     ` Julia Lawall
  2017-08-22 10:00                       ` SF Markus Elfring
  2017-08-23 14:43                     ` SF Markus Elfring
  1 sibling, 1 reply; 33+ messages in thread
From: Julia Lawall @ 2017-08-22  9:28 UTC (permalink / raw)
  To: cocci



On Tue, 22 Aug 2017, SF Markus Elfring wrote:

> >> * Are there further development challenges to consider for the safe identification
> >>   of unique statements by metavariables?
> >
> > If you want to ensure that two metavariables match things
> > in different places, then put a position variable on each match
> > and use apython rule afterwards to discard the occurrences that
> > are both in the same position.
>
> I imagine that such an approach can only matter if there will be
> several SmPL rules involved.
>
>
> I have tried another variant out for a source code analysis.
>
> @duplicated_code@
> identifier work;
> statement s1, s2;
> type T;
> @@
>  T work(...)
>  {
>  <+...
> *if ((...) < 0)
> *{
>     ...
> *   s1
> *   s2
> *}
>  ...+>
>  <+...
> *if ((...) < 0)
> *{
>     ...
> *   s1
> *   s2
> *}
>  ...+>
>  }
>
>
> elfring at Sonne:~/Projekte/Linux/next-patched> XX=$(date) && spatch.opt -timeout 34 -j 4 --chunksize 1 --sp-file ~/Projekte/Coccinelle/janitor/show_same_statements3.cocci --dir sound > ~/Projekte/Bau/Linux/scripts/Coccinelle/tuning1/next/20170803/same_statements3+.diff 2> ~/Projekte/Bau/Linux/scripts/Coccinelle/tuning1/next/20170803/same_statements3+-errors.txt; YY=$(date) && echo "$XX | $YY"
> Di 22. Aug 10:24:47 CEST 2017 | Di 22. Aug 10:26:04 CEST 2017
>
>
> Now I find that a test result like the following is worth for further
> development considerations.
>
> ?
> --- sound/usb/6fire/firmware.c
> +++ /tmp/nothing/usb/6fire/firmware.c
> @@ -246,14 +246,8 @@ static int usb6fire_fw_ezusb_upload(
>  	while (usb6fire_fw_ihex_next_record(rec)) { /* write firmware */
>  		ret = usb6fire_fw_ezusb_write(device, 0xa0, rec->address,
>  				rec->data, rec->len);
> -		if (ret < 0) {
>  			kfree(rec);
>  			release_firmware(fw);
> -			dev_err(&intf->dev,
> -				"unable to upload ezusb firmware %s: data urb.\n",
> -				fwname);
> -			return ret;
> -		}
>  	}
>
>  	release_firmware(fw);
> @@ -319,13 +313,8 @@ static int usb6fire_fw_fpga_upload(
>  			buffer[i] = bitrev8((u8)*c);
>
>  		ret = usb6fire_fw_fpga_write(device, buffer, i);
> -		if (ret < 0) {
>  			release_firmware(fw);
>  			kfree(buffer);
> -			dev_err(&intf->dev,
> -				"unable to upload fpga firmware: fw urb.\n");
> -			return ret;
> -		}
>  	}
>  	release_firmware(fw);
>  	kfree(buffer);
> ?
>
>
> How would you like to treat variations in such log messages?

They look fine as they are.

julia

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

* [Cocci] Comparing statement lists with SmPL
  2017-08-22  9:28                     ` Julia Lawall
@ 2017-08-22 10:00                       ` SF Markus Elfring
       [not found]                         ` <alpine.DEB.2.20.1708221202380.3178@hadrien>
  0 siblings, 1 reply; 33+ messages in thread
From: SF Markus Elfring @ 2017-08-22 10:00 UTC (permalink / raw)
  To: cocci

>> How would you like to treat variations in such log messages?
> 
> They look fine as they are.

I have got other development opinions there depending on the preferred design goals.

* The mentioned small SmPL script can also help to find special differences.

* These log statements are similar (and not identical) in the code structure.
  I wonder also about other marked code places how they would fit to
  the search pattern.

* A test result was shown from two function implementations.
  It can be nice to compare several functions.
  Is it also possible that the comparison will be only performed within
  the same function bodies?

Regards,
Markus

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

* [Cocci] Comparing statement lists with SmPL
       [not found]                         ` <alpine.DEB.2.20.1708221202380.3178@hadrien>
@ 2017-08-22 10:12                           ` SF Markus Elfring
  2017-08-22 10:15                             ` Julia Lawall
  0 siblings, 1 reply; 33+ messages in thread
From: SF Markus Elfring @ 2017-08-22 10:12 UTC (permalink / raw)
  To: cocci

>> * A test result was shown from two function implementations.
>>   It can be nice to compare several functions.
>>   Is it also possible that the comparison will be only performed within
>>   the same function bodies?
> 
> If you make a single rule then it will only applied within individual functions.

How do the presented functions ?usb6fire_fw_ezusb_upload? and ?usb6fire_fw_fpga_upload?
fit to this information?

Regards,
Markus

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

* [Cocci] Comparing statement lists with SmPL
  2017-08-22 10:12                           ` SF Markus Elfring
@ 2017-08-22 10:15                             ` Julia Lawall
  2017-08-22 10:20                               ` SF Markus Elfring
  0 siblings, 1 reply; 33+ messages in thread
From: Julia Lawall @ 2017-08-22 10:15 UTC (permalink / raw)
  To: cocci



On Tue, 22 Aug 2017, SF Markus Elfring wrote:

> >> * A test result was shown from two function implementations.
> >>   It can be nice to compare several functions.
> >>   Is it also possible that the comparison will be only performed within
> >>   the same function bodies?
> >
> > If you make a single rule then it will only applied within individual functions.
>
> How do the presented functions ?usb6fire_fw_ezusb_upload? and ?usb6fire_fw_fpga_upload?
> fit to this information?

The pattern matched in two different functions?

julia

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

* [Cocci] Comparing statement lists with SmPL
  2017-08-22 10:15                             ` Julia Lawall
@ 2017-08-22 10:20                               ` SF Markus Elfring
       [not found]                                 ` <alpine.DEB.2.20.1708221221260.3178@hadrien>
  0 siblings, 1 reply; 33+ messages in thread
From: SF Markus Elfring @ 2017-08-22 10:20 UTC (permalink / raw)
  To: cocci

>> How do the presented functions ?usb6fire_fw_ezusb_upload? and ?usb6fire_fw_fpga_upload?
>> fit to this information?
> 
> The pattern matched in two different functions?

Please look once more.

Yes. - This is one of the reasons why I ask here again.

I would like to choose if a code analysis should happen only within a single function
or on interesting parts from the complete source file.

Regards,
Markus

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

* [Cocci] Comparing statement lists with SmPL
       [not found]                                 ` <alpine.DEB.2.20.1708221221260.3178@hadrien>
@ 2017-08-22 10:33                                   ` SF Markus Elfring
  0 siblings, 0 replies; 33+ messages in thread
From: SF Markus Elfring @ 2017-08-22 10:33 UTC (permalink / raw)
  To: cocci

>>> The pattern matched in two different functions?
>>
>> Please look once more.
>>
>> Yes. - This is one of the reasons why I ask here again.
>>
>> I would like to choose if a code analysis should happen only within a single function
>> or on interesting parts from the complete source file.
> 
> Feel free to make a tool of your own if you are not satisfied with the one
> offered you.

This is also possible. - But I wonder more about specific test results based
on the currently provided software.

I got matches for places where I would expect that they should not match.


> Coccinelle applies a rule to one function at a time.

This is also fine for a while.


> That is not going to change.

I imagine that the situation could evolve more if additional development resources
will appear somehow.


> If you want to match things in different functions, make two rules.

Additional SmPL rules will search for other details.


Regards,
Markus

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

* [Cocci] Comparing statement lists with SmPL
  2017-08-22  9:19                   ` SF Markus Elfring
  2017-08-22  9:28                     ` Julia Lawall
@ 2017-08-23 14:43                     ` SF Markus Elfring
       [not found]                       ` <alpine.DEB.2.20.1708231644340.3150@hadrien>
  1 sibling, 1 reply; 33+ messages in thread
From: SF Markus Elfring @ 2017-08-23 14:43 UTC (permalink / raw)
  To: cocci

> I have tried another variant out for a source code analysis.

Does the following SmPL script variant make sense?

@duplicated_code@
identifier work;
statement s1, s2;
type T;
@@
 T work(...)
 {
 ... when any
*if ((...) < 0)
*{
    ...
*   s1
*   s2
*}
 <+...
*if ((...) < 0)
*{
    ...
*   s1
*   s2
*}
 ...+>
 }


Can this approach find interesting places in any source files?

Regards,
Markus

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

* [Cocci] Comparing statement lists with SmPL
       [not found]                       ` <alpine.DEB.2.20.1708231644340.3150@hadrien>
@ 2017-08-23 15:39                         ` SF Markus Elfring
       [not found]                           ` <alpine.DEB.2.20.1708231742480.3150@hadrien>
  0 siblings, 1 reply; 33+ messages in thread
From: SF Markus Elfring @ 2017-08-23 15:39 UTC (permalink / raw)
  To: cocci

> You would need when any on the ...  Otherwise, it will not match anything
> (perhaps declarations). The s1 after is precludes matching any statement.
> Likewise in the next if.

The suggested variant does still not work in the way I would expect it.

@duplicated_code@
identifier work;
statement s1, s2;
type T;
@@
 T work(...)
 {
 ... when any
*if ((...) < 0)
*{
    ... when any
*   s1
*   s2
*}
 <+...
*if ((...) < 0)
*{
    ... when any
*   s1
*   s2
*}
 ...+>
 }


I got some promising test results from the following SmPL approach.

@duplicated_code@
identifier work;
statement s1, s2;
type T;
@@
 T work(...)
 {
 ... when any
*if ((...) < 0)
*{
    ... when any
*   s1
*   s2
*}
 ... when any
*if ((...) < 0)
*{
    ... when any
*   s1
*   s2
*}
 ... when any
 }


elfring@Sonne:~/Projekte/Linux/next-patched> XX=$(date) && spatch.opt --timeout 12 --sp-file ~/Projekte/Coccinelle/janitor/show_same_statements3b.cocci --dir sound > ~/Projekte/Bau/Linux/scripts/Coccinelle/tuning1/next/20170803/same_statements3b.diff 2> ~/Projekte/Bau/Linux/scripts/Coccinelle/tuning1/next/20170803/same_statements3b-errors.txt; YY=$(date) && echo "$XX | $YY"
Mi 23. Aug 17:25:54 CEST 2017 | Mi 23. Aug 17:29:15 CEST 2017


How should the source code search be improved further here?

Regards,
Markus

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

* [Cocci] Comparing statement lists with SmPL
       [not found]                           ` <alpine.DEB.2.20.1708231742480.3150@hadrien>
@ 2017-08-23 15:50                             ` SF Markus Elfring
  2017-08-24  7:56                             ` SF Markus Elfring
  1 sibling, 0 replies; 33+ messages in thread
From: SF Markus Elfring @ 2017-08-23 15:50 UTC (permalink / raw)
  To: cocci

>> How should the source code search be improved further here?
> 
> If you like the results from the second case, what more do you want?

* There are also several questionable transformation suggestions generated
  besides the usable ones.

* Will answers belong also to the topic ?Get the non-optional nest construct
  completely working for SmPL??
  https://github.com/coccinelle/coccinelle/issues

Regards,
Markus

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

* [Cocci] Comparing statement lists with SmPL
       [not found]                           ` <alpine.DEB.2.20.1708231742480.3150@hadrien>
  2017-08-23 15:50                             ` SF Markus Elfring
@ 2017-08-24  7:56                             ` SF Markus Elfring
  1 sibling, 0 replies; 33+ messages in thread
From: SF Markus Elfring @ 2017-08-24  7:56 UTC (permalink / raw)
  To: cocci

> If you like the results from the second case, what more do you want?

I would like to achieve somehow that the number of presented ?false positives?
will become so low so that similar (and extended) SmPL scripts can be used for
more automatic source code transformations with higher confidence.

* How are are the chances to integrate corresponding variants into a script
  collection for which you care also?
  https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git/tree/scripts/coccinelle/

* How much does the attention for related issues fit to the software development
  capacity which is available so far?

Regards,
Markus

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

end of thread, other threads:[~2017-08-24  7:56 UTC | newest]

Thread overview: 33+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-08-15 17:26 [Cocci] Comparing statement lists with SmPL SF Markus Elfring
2017-08-15 17:33 ` Julia Lawall
2017-08-15 19:04   ` SF Markus Elfring
2017-08-15 19:09     ` Julia Lawall
2017-08-15 19:14       ` SF Markus Elfring
2017-08-15 20:00     ` SF Markus Elfring
2017-08-15 20:09       ` Julia Lawall
2017-08-15 20:15         ` SF Markus Elfring
2017-08-16  6:48         ` SF Markus Elfring
2017-08-16  7:03           ` SF Markus Elfring
2017-08-16  9:20             ` Julia Lawall
2017-08-16 10:42               ` SF Markus Elfring
2017-08-16  9:01           ` Julia Lawall
2017-08-16  7:35         ` SF Markus Elfring
2017-08-17 17:54           ` SF Markus Elfring
2017-08-17 18:44             ` Julia Lawall
2017-08-17 19:26               ` SF Markus Elfring
2017-08-17 19:31                 ` Julia Lawall
2017-08-17 19:43                   ` SF Markus Elfring
2017-08-22  9:19                   ` SF Markus Elfring
2017-08-22  9:28                     ` Julia Lawall
2017-08-22 10:00                       ` SF Markus Elfring
     [not found]                         ` <alpine.DEB.2.20.1708221202380.3178@hadrien>
2017-08-22 10:12                           ` SF Markus Elfring
2017-08-22 10:15                             ` Julia Lawall
2017-08-22 10:20                               ` SF Markus Elfring
     [not found]                                 ` <alpine.DEB.2.20.1708221221260.3178@hadrien>
2017-08-22 10:33                                   ` SF Markus Elfring
2017-08-23 14:43                     ` SF Markus Elfring
     [not found]                       ` <alpine.DEB.2.20.1708231644340.3150@hadrien>
2017-08-23 15:39                         ` SF Markus Elfring
     [not found]                           ` <alpine.DEB.2.20.1708231742480.3150@hadrien>
2017-08-23 15:50                             ` SF Markus Elfring
2017-08-24  7:56                             ` SF Markus Elfring
2017-08-16  6:10   ` SF Markus Elfring
2017-08-16  6:26     ` Julia Lawall
2017-08-16  6:38       ` 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.