Skip to contentSkip to conversation

Deleting unused declarations for variables with SmPL?

Cocci SF Markus Elfring 2 participants 5 messages Dec 25, 2018 – Dec 28, 2018 11 messages not in the archive

lore
Share & tools
lore
#0 lore raw

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
[email protected]
https://systeme.lip6.fr/mailman/listinfo/cocci

#1 lore raw
Quoted 10 lines · SF Markus Elfring

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

Quoted 19 lines

elfring@Sonne:~/Projekte/Linux/next-patched> spatch ~/Projekte/Coccinelle/Probe/delete_unused_variable1.cocci init/main.c …

(quoted diff) +0 -4
@@ -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?

Quoted 7 lines

Regards,
Markus
_______________________________________________
Cocci mailing list
[email protected]
https://systeme.lip6.fr/mailman/listinfo/cocci

_______________________________________________
Cocci mailing list
[email protected]
https://systeme.lip6.fr/mailman/listinfo/cocci

A message that is not in the archive (sent off-list or not yet received): [email protected]

#3 lore raw
Quoted 9 lines · SF Markus Elfring
Quoted 5 lines
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
[email protected]
https://systeme.lip6.fr/mailman/listinfo/cocci

A message that is not in the archive (sent off-list or not yet received): [email protected]

A message that is not in the archive (sent off-list or not yet received): alpine.DEB.2.21.1812251700080.8365@hadrien

A message that is not in the archive (sent off-list or not yet received): [email protected]

A message that is not in the archive (sent off-list or not yet received): alpine.DEB.2.21.1812251734590.8365@hadrien

A message that is not in the archive (sent off-list or not yet received): [email protected]

A message that is not in the archive (sent off-list or not yet received): [email protected]

A message that is not in the archive (sent off-list or not yet received): alpine.DEB.2.21.1812251823440.8365@hadrien

A message that is not in the archive (sent off-list or not yet received): [email protected]

A message that is not in the archive (sent off-list or not yet received): alpine.DEB.2.21.1812271622350.2457@hadrien

A message that is not in the archive (sent off-list or not yet received): [email protected]

#14 lore raw
Quoted 17 lines · SF Markus Elfring
Quoted 1 line

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
}

Quoted 12 lines

@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
[email protected]
https://systeme.lip6.fr/mailman/listinfo/cocci

#15 lore raw
In reply to a message not in the archive
Quoted 10 lines

@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
[email protected]
https://systeme.lip6.fr/mailman/listinfo/cocci