cocci.inria.fr archive mirror
 help / color / mirror / Atom feed
* [Cocci] continue statement of death?
@ 2019-09-12  1:51 David Young
  2019-09-12  8:27 ` Julia Lawall
  2019-09-12 13:37 ` Markus Elfring
  0 siblings, 2 replies; 5+ messages in thread
From: David Young @ 2019-09-12  1:51 UTC (permalink / raw)
  To: cocci

Today I built and installed Coccinelle 1.0.7 on NetBSD.

I am processing this fragment of NetBSD kernel code, `tbr_timeout.c`,

| /*
|  * tbr_timeout goes through the interface list, and kicks the drivers
|  * if necessary.
|  */
| static void
| tbr_timeout(void *arg)
| {
|         struct ifnet *ifp;
|         int active, s;
| 
|         active = 0;
|         s = splnet();
|         for (ifp = TAILQ_FIRST(&ifnet); ifp; ifp = TAILQ_NEXT(ifp, if_list)) {
|                 if (!TBR_IS_ENABLED(&ifp->if_snd))
| #if 1
|                         continue;
| #endif
|                 active++;
|                 if (!IFQ_IS_EMPTY(&ifp->if_snd) && ifp->if_start != NULL)
|                         (*ifp->if_start)(ifp);
|         }
|         splx(s);
|         if (active > 0)
|                 CALLOUT_RESET(&tbr_callout, 1, tbr_timeout, NULL);
|         else
|                 tbr_timer = 0;  /* don't need tbr_timer anymore */
| }
| 

using this semantic patch, `tailq.spatch`,

| @@
| identifier I, N;
| expression H;
| statement S;
| iterator name TAILQ_FOREACH;
| @@
| 
| - for (I = TAILQ_FIRST(H); I != NULL; I = TAILQ_NEXT(I, N)) S
| + TAILQ_FOREACH(I, H, N) S

I find that if the condition in the `#if` directive is 1, then `spatch
--sp-file tailq.spatch -o tbr_timeout.spatch tbr_timeout.c` runs for
a few minutes before running out of memory. `spatch` prints this
mysterious message when it starts:

     (ONCE) already tagged but only removed, so safe

If I turn the condition to 0, however, spatch instantaneously prints the
result with the `for (...)` clause turned to `TAILQ_FOREACH(...)`, as
expected.  I don't see the mysterious `(ONCE) ...` message.

Any ideas why `continue;` is troublesome to spatch?

Dave

-- 
David Young
dyoung@pobox.com    Urbana, IL    (217) 721-9981
_______________________________________________
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] continue statement of death?
  2019-09-12  1:51 [Cocci] continue statement of death? David Young
@ 2019-09-12  8:27 ` Julia Lawall
  2019-09-12 13:37 ` Markus Elfring
  1 sibling, 0 replies; 5+ messages in thread
From: Julia Lawall @ 2019-09-12  8:27 UTC (permalink / raw)
  To: David Young; +Cc: cocci



On Wed, 11 Sep 2019, David Young wrote:

> Today I built and installed Coccinelle 1.0.7 on NetBSD.
>
> I am processing this fragment of NetBSD kernel code, `tbr_timeout.c`,
>
> | /*
> |  * tbr_timeout goes through the interface list, and kicks the drivers
> |  * if necessary.
> |  */
> | static void
> | tbr_timeout(void *arg)
> | {
> |         struct ifnet *ifp;
> |         int active, s;
> |
> |         active = 0;
> |         s = splnet();
> |         for (ifp = TAILQ_FIRST(&ifnet); ifp; ifp = TAILQ_NEXT(ifp, if_list)) {
> |                 if (!TBR_IS_ENABLED(&ifp->if_snd))
> | #if 1
> |                         continue;
> | #endif
> |                 active++;
> |                 if (!IFQ_IS_EMPTY(&ifp->if_snd) && ifp->if_start != NULL)
> |                         (*ifp->if_start)(ifp);
> |         }
> |         splx(s);
> |         if (active > 0)
> |                 CALLOUT_RESET(&tbr_callout, 1, tbr_timeout, NULL);
> |         else
> |                 tbr_timer = 0;  /* don't need tbr_timer anymore */
> | }
> |
>
> using this semantic patch, `tailq.spatch`,
>
> | @@
> | identifier I, N;
> | expression H;
> | statement S;
> | iterator name TAILQ_FOREACH;
> | @@
> |
> | - for (I = TAILQ_FIRST(H); I != NULL; I = TAILQ_NEXT(I, N)) S
> | + TAILQ_FOREACH(I, H, N) S
>
> I find that if the condition in the `#if` directive is 1, then `spatch
> --sp-file tailq.spatch -o tbr_timeout.spatch tbr_timeout.c` runs for
> a few minutes before running out of memory. `spatch` prints this
> mysterious message when it starts:
>
>      (ONCE) already tagged but only removed, so safe
>
> If I turn the condition to 0, however, spatch instantaneously prints the
> result with the `for (...)` clause turned to `TAILQ_FOREACH(...)`, as
> expected.  I don't see the mysterious `(ONCE) ...` message.
>
> Any ideas why `continue;` is troublesome to spatch?

I'm looking into it.  It seems to be a pretty printing problem.

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] continue statement of death?
  2019-09-12  1:51 [Cocci] continue statement of death? David Young
  2019-09-12  8:27 ` Julia Lawall
@ 2019-09-12 13:37 ` Markus Elfring
  2019-09-12 14:49   ` David Young
  2019-09-12 14:51   ` Julia Lawall
  1 sibling, 2 replies; 5+ messages in thread
From: Markus Elfring @ 2019-09-12 13:37 UTC (permalink / raw)
  To: cocci, David Young

>  - for (I = TAILQ_FIRST(H); I != NULL; I = TAILQ_NEXT(I, N)) S
>  + TAILQ_FOREACH(I, H, N) S

Can it make sense to avoid touching the (compound) statement at the end
so that only the loop header would be replaced?

-for (I = TAILQ_FIRST(H); I != NULL; I = TAILQ_NEXT(I, N))
+TAILQ_FOREACH(I, H, N)
 S


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] continue statement of death?
  2019-09-12 13:37 ` Markus Elfring
@ 2019-09-12 14:49   ` David Young
  2019-09-12 14:51   ` Julia Lawall
  1 sibling, 0 replies; 5+ messages in thread
From: David Young @ 2019-09-12 14:49 UTC (permalink / raw)
  To: cocci

On Thu, Sep 12, 2019 at 03:37:42PM +0200, Markus Elfring wrote:
> >  - for (I = TAILQ_FIRST(H); I != NULL; I = TAILQ_NEXT(I, N)) S
> >  + TAILQ_FOREACH(I, H, N) S
> 
> Can it make sense to avoid touching the (compound) statement at the end
> so that only the loop header would be replaced?
> 
> -for (I = TAILQ_FIRST(H); I != NULL; I = TAILQ_NEXT(I, N))
> +TAILQ_FOREACH(I, H, N)
>  S

Sure, that's a reasonable way to refactor the semantic patch.  That
works around the bug, too.

Dave

-- 
David Young
dyoung@pobox.com    Urbana, IL    (217) 721-9981
_______________________________________________
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] continue statement of death?
  2019-09-12 13:37 ` Markus Elfring
  2019-09-12 14:49   ` David Young
@ 2019-09-12 14:51   ` Julia Lawall
  1 sibling, 0 replies; 5+ messages in thread
From: Julia Lawall @ 2019-09-12 14:51 UTC (permalink / raw)
  To: Markus Elfring; +Cc: cocci



On Thu, 12 Sep 2019, Markus Elfring wrote:

> >  - for (I = TAILQ_FIRST(H); I != NULL; I = TAILQ_NEXT(I, N)) S
> >  + TAILQ_FOREACH(I, H, N) S
>
> Can it make sense to avoid touching the (compound) statement at the end
> so that only the loop header would be replaced?
>
> -for (I = TAILQ_FIRST(H); I != NULL; I = TAILQ_NEXT(I, N))
> +TAILQ_FOREACH(I, H, N)
>  S

This does indeed seem to avoid the problem.  Nevertheless, it is useful to
have the problem reported in the first place.

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, other threads:[~2019-09-12 15:05 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-09-12  1:51 [Cocci] continue statement of death? David Young
2019-09-12  8:27 ` Julia Lawall
2019-09-12 13:37 ` Markus Elfring
2019-09-12 14:49   ` David Young
2019-09-12 14:51   ` Julia Lawall

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).