* [Cocci] keeping cast affects match?
@ 2016-02-17 14:45 Wolfram Sang
2016-02-17 14:51 ` Julia Lawall
0 siblings, 1 reply; 5+ messages in thread
From: Wolfram Sang @ 2016-02-17 14:45 UTC (permalink / raw)
To: cocci
Hi,
using Coccinelle v1.04 from Debian:
$ spatch -version
spatch version 1.0.4 with Python support and with PCRE support
The following semantic patch produces a match with current linux-next:
@@
expression table, dev;
type T;
@@
- (T)of_match_device(table, dev)->data
+ of_device_get_match_data(dev)
$ spatch -sp_file minimal.cocci drivers/gpu/drm/rcar-du/
...
HANDLING: drivers/gpu/drm/rcar-du/rcar_du_drv.c
diff =
diff -u -p a/rcar_du_drv.c b/rcar_du_drv.c
--- a/rcar_du_drv.c
+++ b/rcar_du_drv.c
@@ -183,7 +183,7 @@ static int rcar_du_load(struct drm_devic
init_waitqueue_head(&rcdu->commit.wait);
rcdu->dev = &pdev->dev;
- rcdu->info = of_match_device(rcar_du_of_table, rcdu->dev)->data;
+ rcdu->info = of_device_get_match_data(rcdu->dev);
rcdu->ddev = dev;
dev->dev_private = rcdu;
However, the match goes away when I want to keep a potential cast (T) which I
need in other places:
@@
expression table, dev;
type T;
@@
- (T)of_match_device(table, dev)->data
+ (T)of_device_get_match_data(dev)
I wonder why adding (T) to "+" affects the matching. Is this a bug or do I miss
something?
Thanks,
Wolfram
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <https://systeme.lip6.fr/pipermail/cocci/attachments/20160217/e4363821/attachment.asc>
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Cocci] keeping cast affects match?
2016-02-17 14:45 [Cocci] keeping cast affects match? Wolfram Sang
@ 2016-02-17 14:51 ` Julia Lawall
2016-02-17 15:07 ` Wolfram Sang
0 siblings, 1 reply; 5+ messages in thread
From: Julia Lawall @ 2016-02-17 14:51 UTC (permalink / raw)
To: cocci
On Wed, 17 Feb 2016, Wolfram Sang wrote:
> Hi,
>
> using Coccinelle v1.04 from Debian:
>
> $ spatch -version
> spatch version 1.0.4 with Python support and with PCRE support
>
> The following semantic patch produces a match with current linux-next:
>
> @@
> expression table, dev;
> type T;
> @@
> - (T)of_match_device(table, dev)->data
> + of_device_get_match_data(dev)
>
>
> $ spatch -sp_file minimal.cocci drivers/gpu/drm/rcar-du/
> ...
> HANDLING: drivers/gpu/drm/rcar-du/rcar_du_drv.c
> diff =
> diff -u -p a/rcar_du_drv.c b/rcar_du_drv.c
> --- a/rcar_du_drv.c
> +++ b/rcar_du_drv.c
> @@ -183,7 +183,7 @@ static int rcar_du_load(struct drm_devic
> init_waitqueue_head(&rcdu->commit.wait);
>
> rcdu->dev = &pdev->dev;
> - rcdu->info = of_match_device(rcar_du_of_table, rcdu->dev)->data;
> + rcdu->info = of_device_get_match_data(rcdu->dev);
> rcdu->ddev = dev;
> dev->dev_private = rcdu;
>
> However, the match goes away when I want to keep a potential cast (T) which I
> need in other places:
>
> @@
> expression table, dev;
> type T;
> @@
> - (T)of_match_device(table, dev)->data
> + (T)of_device_get_match_data(dev)
>
> I wonder why adding (T) to "+" affects the matching. Is this a bug or do I miss
> something?
The isomorphism that allows ignoring a cast only works when the type
metavariable is used only once. You uare using it twice. The fact that
you wanted to add it indicates that you really want it to be there.
I think that everything should be fine if you just move the (T) out of the
removed and added code.
julia
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Cocci] keeping cast affects match?
2016-02-17 14:51 ` Julia Lawall
@ 2016-02-17 15:07 ` Wolfram Sang
2016-02-17 15:12 ` Julia Lawall
0 siblings, 1 reply; 5+ messages in thread
From: Wolfram Sang @ 2016-02-17 15:07 UTC (permalink / raw)
To: cocci
> The isomorphism that allows ignoring a cast only works when the type
> metavariable is used only once. You uare using it twice. The fact that
> you wanted to add it indicates that you really want it to be there.
Aha, I understand. Thank you for the explanation!
> I think that everything should be fine if you just move the (T) out of the
> removed and added code.
Much better! I still fall for thinking too much in terms of 'lines'
instead of 'tokens'. Prompt and proper response (again) much
appreciated. Thank you a ton!
Wolfram
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <https://systeme.lip6.fr/pipermail/cocci/attachments/20160217/9eb5ae14/attachment.asc>
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Cocci] keeping cast affects match?
2016-02-17 15:07 ` Wolfram Sang
@ 2016-02-17 15:12 ` Julia Lawall
2016-02-17 15:19 ` Wolfram Sang
0 siblings, 1 reply; 5+ messages in thread
From: Julia Lawall @ 2016-02-17 15:12 UTC (permalink / raw)
To: cocci
On Wed, 17 Feb 2016, Wolfram Sang wrote:
> > The isomorphism that allows ignoring a cast only works when the type
> > metavariable is used only once. You uare using it twice. The fact that
> > you wanted to add it indicates that you really want it to be there.
>
> Aha, I understand. Thank you for the explanation!
>
> > I think that everything should be fine if you just move the (T) out of the
> > removed and added code.
>
> Much better! I still fall for thinking too much in terms of 'lines'
> instead of 'tokens'. Prompt and proper response (again) much
> appreciated. Thank you a ton!
It's worth thinking twice if you find yourself removing something to add
it back. Sometimes it's just more convenient, or even useful, because
Coccinelle is pretty good now at inserting newlines in the right place for
long argument lists, but when it is at one end or another of the pattern
like this, it can be better to just pull the common part out into the
context.
julia
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Cocci] keeping cast affects match?
2016-02-17 15:12 ` Julia Lawall
@ 2016-02-17 15:19 ` Wolfram Sang
0 siblings, 0 replies; 5+ messages in thread
From: Wolfram Sang @ 2016-02-17 15:19 UTC (permalink / raw)
To: cocci
> like this, it can be better to just pull the common part out into the
> context.
That was definately the case here. After doing that for the other three
rules I had, two of them became identical :) Also, I got more matches,
because there was context I had not anticipated yet. Big win!
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <https://systeme.lip6.fr/pipermail/cocci/attachments/20160217/d74e0b87/attachment.asc>
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2016-02-17 15:19 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-02-17 14:45 [Cocci] keeping cast affects match? Wolfram Sang
2016-02-17 14:51 ` Julia Lawall
2016-02-17 15:07 ` Wolfram Sang
2016-02-17 15:12 ` Julia Lawall
2016-02-17 15:19 ` Wolfram Sang
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.