All of lore.kernel.org
 help / color / mirror / Atom feed
* [Cocci] Finding labelled statements with SmPL
@ 2015-12-09  9:20 SF Markus Elfring
  2015-12-09 10:15 ` Julia Lawall
  0 siblings, 1 reply; 5+ messages in thread
From: SF Markus Elfring @ 2015-12-09  9:20 UTC (permalink / raw)
  To: cocci

Hello,

I have tried another small SmPL script out.

@label_used@
identifier target, work;
type return_type;
@@
 return_type work(...)
 {
 ... when any
*target:
 ... when any
 }


Test example:
https://git.kernel.org/cgit/linux/kernel/git/next/linux-next.git/tree/drivers/block/skd_main.c

elfring at Sonne:~/Projekte/Coccinelle/janitor> spatch.opt show_labels1.cocci ~/Projekte/Linux/next-patched/drivers/block/skd_main.c
?
@@ -778,7 +778,6 @@ static void skd_request_fn(struct reques
                        continue;
                }
 
-skip_sg:
                scsi_req->hdr.sg_list_len_bytes =
                        cpu_to_be32(skreq->sg_byte_count);
 
?
@@ -5114,10 +5094,8 @@ err_out_iounmap:
        if (skdev->pcie_error_reporting_is_enabled)
                pci_disable_pcie_error_reporting(pdev);
 
-err_out_regions:
        pci_release_regions(pdev);
 
-err_out:
        pci_disable_device(pdev);
        return rc;
 }


It seems that only jump labels are found by the shown source code analysis
approach so far.
http://en.cppreference.com/w/c/language/goto

Does an enumeration symbol like "SKD_IRQ_MSIX" fit to the properties of
a C identifier?


I imagine that case labels could also be matched by such a simple search pattern.
http://en.cppreference.com/w/c/language/switch
http://c0x.coding-guidelines.com/6.8.1.html

@label_used@
expression label;
identifier work;
type return_type;
@@
 return_type work(...)
 {
 ... when any
*label:
 ... when any
 }


elfring at Sonne:~/Projekte/Coccinelle/janitor> spatch.opt show_labels2.cocci ~/Projekte/Linux/next-patched/drivers/block/skd_main.c
init_defs_builtins: /usr/local/lib64/coccinelle/standard.h
115 116
Fatal error: exception Failure("minus: parse error: \n = File \"show_labels2.cocci\", line 9, column 6,  charpos = 115\n    around = ':', whole content = *label:\n")


Would you like to clarify these observations?

Regards,
Markus

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

* [Cocci] Finding labelled statements with SmPL
  2015-12-09  9:20 [Cocci] Finding labelled statements with SmPL SF Markus Elfring
@ 2015-12-09 10:15 ` Julia Lawall
  2015-12-09 12:00   ` SF Markus Elfring
  0 siblings, 1 reply; 5+ messages in thread
From: Julia Lawall @ 2015-12-09 10:15 UTC (permalink / raw)
  To: cocci

A label has to be an identifier.  A sequence of all capital letters is
also an identifier.

julia

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

> Hello,
>
> I have tried another small SmPL script out.
>
> @label_used@
> identifier target, work;
> type return_type;
> @@
>  return_type work(...)
>  {
>  ... when any
> *target:
>  ... when any
>  }
>
>
> Test example:
> https://git.kernel.org/cgit/linux/kernel/git/next/linux-next.git/tree/drivers/block/skd_main.c
>
> elfring at Sonne:~/Projekte/Coccinelle/janitor> spatch.opt show_labels1.cocci ~/Projekte/Linux/next-patched/drivers/block/skd_main.c
> ?
> @@ -778,7 +778,6 @@ static void skd_request_fn(struct reques
>                         continue;
>                 }
>
> -skip_sg:
>                 scsi_req->hdr.sg_list_len_bytes =
>                         cpu_to_be32(skreq->sg_byte_count);
>
> ?
> @@ -5114,10 +5094,8 @@ err_out_iounmap:
>         if (skdev->pcie_error_reporting_is_enabled)
>                 pci_disable_pcie_error_reporting(pdev);
>
> -err_out_regions:
>         pci_release_regions(pdev);
>
> -err_out:
>         pci_disable_device(pdev);
>         return rc;
>  }
>
>
> It seems that only jump labels are found by the shown source code analysis
> approach so far.
> http://en.cppreference.com/w/c/language/goto
>
> Does an enumeration symbol like "SKD_IRQ_MSIX" fit to the properties of
> a C identifier?
>
>
> I imagine that case labels could also be matched by such a simple search pattern.
> http://en.cppreference.com/w/c/language/switch
> http://c0x.coding-guidelines.com/6.8.1.html
>
> @label_used@
> expression label;
> identifier work;
> type return_type;
> @@
>  return_type work(...)
>  {
>  ... when any
> *label:
>  ... when any
>  }
>
>
> elfring at Sonne:~/Projekte/Coccinelle/janitor> spatch.opt show_labels2.cocci ~/Projekte/Linux/next-patched/drivers/block/skd_main.c
> init_defs_builtins: /usr/local/lib64/coccinelle/standard.h
> 115 116
> Fatal error: exception Failure("minus: parse error: \n = File \"show_labels2.cocci\", line 9, column 6,  charpos = 115\n    around = ':', whole content = *label:\n")
>
>
> Would you like to clarify these observations?
>
> Regards,
> Markus
> _______________________________________________
> Cocci mailing list
> Cocci at systeme.lip6.fr
> https://systeme.lip6.fr/mailman/listinfo/cocci
>

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

* [Cocci] Finding labelled statements with SmPL
  2015-12-09 10:15 ` Julia Lawall
@ 2015-12-09 12:00   ` SF Markus Elfring
  2015-12-09 12:54     ` Julia Lawall
  0 siblings, 1 reply; 5+ messages in thread
From: SF Markus Elfring @ 2015-12-09 12:00 UTC (permalink / raw)
  To: cocci

> A label has to be an identifier.

This wording fits only to a jump label for the statement "goto", doesn't it?


> A sequence of all capital letters is also an identifier.

Does this feedback mean that the following SmPL approach should also work
for case labels?


@label_used@
identifier label;
@@
*label:


How much do constant expressions matter in such a source code analysis?

Why did I get the message "minus: parse error"?

Regards,
Markus

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

* [Cocci] Finding labelled statements with SmPL
  2015-12-09 12:00   ` SF Markus Elfring
@ 2015-12-09 12:54     ` Julia Lawall
  2015-12-09 14:01       ` SF Markus Elfring
  0 siblings, 1 reply; 5+ messages in thread
From: Julia Lawall @ 2015-12-09 12:54 UTC (permalink / raw)
  To: cocci



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

> > A label has to be an identifier.
>
> This wording fits only to a jump label for the statement "goto", doesn't it?

The labels for switch have "case" in front of them.  They won't be matched
by a pattern like label:

>
> > A sequence of all capital letters is also an identifier.
>
> Does this feedback mean that the following SmPL approach should also work
> for case labels?
>
>
> @label_used@
> identifier label;
> @@
> *label:
>
>
> How much do constant expressions matter in such a source code analysis?
>
> Why did I get the message "minus: parse error"?

Probably because a label by itself is not valid C code.  It needs a
statement after it.

julia

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

* [Cocci] Finding labelled statements with SmPL
  2015-12-09 12:54     ` Julia Lawall
@ 2015-12-09 14:01       ` SF Markus Elfring
  0 siblings, 0 replies; 5+ messages in thread
From: SF Markus Elfring @ 2015-12-09 14:01 UTC (permalink / raw)
  To: cocci

> The labels for switch have "case" in front of them.  They won't be matched
> by a pattern like label:

I would expect that the key word "case" can be optional because such source
code should be matched by the specified SmPL ellipsis.

Regards,
Markus

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

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

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-12-09  9:20 [Cocci] Finding labelled statements with SmPL SF Markus Elfring
2015-12-09 10:15 ` Julia Lawall
2015-12-09 12:00   ` SF Markus Elfring
2015-12-09 12:54     ` Julia Lawall
2015-12-09 14:01       ` 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.