Coccinelle archive on lore.kernel.org
 help / Atom feed
* [Cocci] Deleting unused declarations for variables with SmPL?
@ 2018-12-25 13:40 SF Markus Elfring
  2018-12-25 13:45 ` Julia Lawall
  0 siblings, 1 reply; 5+ messages in thread
From: SF Markus Elfring @ 2018-12-25 13:40 UTC (permalink / raw)
  To: Coccinelle

Hello,

I have tried another simple script out for the semantic patch language.

@deletion@
identifier x;
type t;
@@
-t x;
 ... when != x


elfring@Sonne:~/Projekte/Linux/next-patched> spatch ~/Projekte/Coccinelle/Probe/delete_unused_variable1.cocci init/main.c
…
@@ -101,22 +101,6 @@
 
 #define CREATE_TRACE_POINTS
 #include <trace/events/initcall.h>
-
-static int kernel_init(void *);
-
-extern void init_IRQ(void);
…


Now I wonder about the generated change suggestions.
Does such a transformation approach need any extensions for the safe handling
of function declarations?

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

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

* Re: [Cocci] Deleting unused declarations for variables with SmPL?
  2018-12-25 13:40 [Cocci] Deleting unused declarations for variables with SmPL? SF Markus Elfring
@ 2018-12-25 13:45 ` Julia Lawall
       [not found]   ` <7d528a6a-33fd-c8ff-e703-c8ff47908e90@users.sourceforge.net>
       [not found]   ` <a6c91cf5-4ff3-9088-0b58-b0039e495d58@users.sourceforge.net>
  0 siblings, 2 replies; 5+ messages in thread
From: Julia Lawall @ 2018-12-25 13:45 UTC (permalink / raw)
  To: SF Markus Elfring; +Cc: Coccinelle

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



On Tue, 25 Dec 2018, SF Markus Elfring wrote:

> Hello,
>
> I have tried another simple script out for the semantic patch language.
>
> @deletion@
> identifier x;
> type t;
> @@
> -t x;
>  ... when != x

f(...) {
   ... when any
   t x;
   ... when != x
}

julia


>
>
> elfring@Sonne:~/Projekte/Linux/next-patched> spatch ~/Projekte/Coccinelle/Probe/delete_unused_variable1.cocci init/main.c
> …
> @@ -101,22 +101,6 @@
>
>  #define CREATE_TRACE_POINTS
>  #include <trace/events/initcall.h>
> -
> -static int kernel_init(void *);
> -
> -extern void init_IRQ(void);
> …
>
>
> Now I wonder about the generated change suggestions.
> Does such a transformation approach need any extensions for the safe handling
> of function declarations?
>
> Regards,
> Markus
> _______________________________________________
> Cocci mailing list
> Cocci@systeme.lip6.fr
> https://systeme.lip6.fr/mailman/listinfo/cocci
>
[-- Attachment #2: 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] 5+ messages in thread

* Re: [Cocci] Deleting unused declarations for variables with SmPL?
       [not found]   ` <7d528a6a-33fd-c8ff-e703-c8ff47908e90@users.sourceforge.net>
@ 2018-12-25 14:09     ` Julia Lawall
  0 siblings, 0 replies; 5+ messages in thread
From: Julia Lawall @ 2018-12-25 14:09 UTC (permalink / raw)
  To: SF Markus Elfring; +Cc: Coccinelle



On Tue, 25 Dec 2018, SF Markus Elfring wrote:

> > f(...) {
> >    ... when any
> >    t x;
> >    ... when != x
> > }
>
> I wonder about the need to wrap a bit of SmPL code by a function skeleton.
> Should the Coccinelle software handle the shown source code search
> also without such an addition?

Apprently not, as shown by your experiment.  Declarations can appear at
top level and in functions, and Coccinelle doesn't know which you want.

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

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

* Re: [Cocci] Deleting unused declarations for variables with SmPL?
       [not found]                     ` <36f19c49-a6e9-11f1-2bb8-c22ad3ca8e54@users.sourceforge.net>
@ 2018-12-27 19:49                       ` Julia Lawall
  2018-12-28  9:50                       ` Julia Lawall
  1 sibling, 0 replies; 5+ messages in thread
From: Julia Lawall @ 2018-12-27 19:49 UTC (permalink / raw)
  To: SF Markus Elfring; +Cc: Coccinelle



On Thu, 27 Dec 2018, SF Markus Elfring wrote:

> > If you have a problem, provide a complete example.
>
> Do you find software development difficulties easier
> to clarify based on source code analysis by a SmPL script
> like the following?
>
> @find@
> identifier f, x;
> type ft, xt;
> @@
>  ft f(...)
>  {
>  ... when any
>  xt x;
>  ... when != x
>  }
>
> @show@
> identifier find.f, find.x;
> type find.ft, find.xt;
> @@
>  ft f(...)
>  {
>  ... when any
>  xt x;
>  ...
> *x
>  ...
>  }

I don't know what you expect the second rule to do, but it will only match
when there exists a control-flow path through the function where x is
referenced exactly once.

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

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

* Re: [Cocci] Deleting unused declarations for variables with SmPL?
       [not found]                     ` <36f19c49-a6e9-11f1-2bb8-c22ad3ca8e54@users.sourceforge.net>
  2018-12-27 19:49                       ` Julia Lawall
@ 2018-12-28  9:50                       ` Julia Lawall
  1 sibling, 0 replies; 5+ messages in thread
From: Julia Lawall @ 2018-12-28  9:50 UTC (permalink / raw)
  To: SF Markus Elfring; +Cc: Coccinelle

> @find@
> identifier f, x;
> type ft, xt;
> @@
>  ft f(...)
>  {
>  ... when any
>  xt x;
>  ... when != x
>  }

If you put when strict additionally on the second ..., then everything
should be fine.  Without when strict, it will skip over error handling
code (an if with only a then branch that ends with some kind of jump) if
doing so is necessary to get a match.

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

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

end of thread, back to index

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-12-25 13:40 [Cocci] Deleting unused declarations for variables with SmPL? SF Markus Elfring
2018-12-25 13:45 ` Julia Lawall
     [not found]   ` <7d528a6a-33fd-c8ff-e703-c8ff47908e90@users.sourceforge.net>
2018-12-25 14:09     ` Julia Lawall
     [not found]   ` <a6c91cf5-4ff3-9088-0b58-b0039e495d58@users.sourceforge.net>
     [not found]     ` <alpine.DEB.2.21.1812251700080.8365@hadrien>
     [not found]       ` <88be4433-a617-056e-3dee-495a41e46110@users.sourceforge.net>
     [not found]         ` <alpine.DEB.2.21.1812251734590.8365@hadrien>
     [not found]           ` <afd513b0-e16a-a5ca-088f-244a31097f9d@users.sourceforge.net>
     [not found]             ` <f1884111-1762-b96e-7f08-c327704e5ba0@users.sourceforge.net>
     [not found]               ` <alpine.DEB.2.21.1812251823440.8365@hadrien>
     [not found]                 ` <ff650b4e-5058-e2d6-9815-4f8372ed32c1@users.sourceforge.net>
     [not found]                   ` <alpine.DEB.2.21.1812271622350.2457@hadrien>
     [not found]                     ` <36f19c49-a6e9-11f1-2bb8-c22ad3ca8e54@users.sourceforge.net>
2018-12-27 19:49                       ` Julia Lawall
2018-12-28  9:50                       ` Julia Lawall

Coccinelle archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/cocci/0 cocci/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 cocci cocci/ https://lore.kernel.org/cocci \
		cocci@systeme.lip6.fr cocci@archiver.kernel.org
	public-inbox-index cocci


Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/fr.lip6.systeme.cocci


AGPL code for this site: git clone https://public-inbox.org/ public-inbox