All of lore.kernel.org
 help / color / mirror / Atom feed
* [Cocci] replace waserror/error with goto fail
@ 2014-06-09 22:04 ron minnich
  2014-06-10  6:23 ` Julia Lawall
  0 siblings, 1 reply; 2+ messages in thread
From: ron minnich @ 2014-06-09 22:04 UTC (permalink / raw)
  To: cocci

I have a lot of code with this sort of thing:

if (waserror()) {
    error stuff
}

if waserror() {
   more error stuff
   nexterror() goes to first waserror
}

if (bad2) error() // goes to second waserror

poperror()

if (bad1) error() // goes to first error

Now, by inspection, one can unwind this stuff but ... any thoughts on
whether this is doable by spatch?

This could get transformed into:

if (bad2) goto fail2

if (bad1) goto fail1

fail2:
  fail2 stuff
fail1:
   fail1 stuff



Thanks

ron
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://systeme.lip6.fr/pipermail/cocci/attachments/20140609/e55151d9/attachment.html>

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

* [Cocci] replace waserror/error with goto fail
  2014-06-09 22:04 [Cocci] replace waserror/error with goto fail ron minnich
@ 2014-06-10  6:23 ` Julia Lawall
  0 siblings, 0 replies; 2+ messages in thread
From: Julia Lawall @ 2014-06-10  6:23 UTC (permalink / raw)
  To: cocci



On Mon, 9 Jun 2014, ron minnich wrote:

> I have a lot of code with this sort of thing:
> if (waserror()) {
> ? ? error stuff
> }
>
> if waserror() {
> ? ?more error stuff
> ? ?nexterror() goes to first waserror
> }
>
> if (bad2) error() // goes to second waserror
>
> poperror()
>
> if (bad1) error() // goes to first error

Could you be more concrete?

Coccinelle is unfortunately not very good at arbitrary sequences of
statements.  If the code you are describing is line the code in the Linux
kernel, where you have

if (error)
  A
  return fail;
...
if (error)
  A
  B
  return fail
...
if (error)
  A
  B
  C
  return fail

that you want to convert to:

err3: C
err2: B
err1: A
      return fail

then this would be hard for Coccinelle.  You could somehow make a rule to
pick up each of the statements individually in the error handling code,
but since there is an arbitrary number of them, there would be no way to
be sure to drop them down in the error handling code in the right order.

I had a student who made a tool to do exactly the above transformation.
If this is what you want to do, I can see if he could resurrect the code.

The tool is described in the following paper:

Suman Saha, Julia L. Lawall, Gilles Muller: An approach to improving the
structure of error-handling code in the linux kernel. LCTES 2011: 41-50

julia

> Now, by inspection, one can unwind this stuff but ... any thoughts on
> whether this is doable by spatch??
>
> This could get transformed into:
>
> if (bad2) goto fail2
>
> if (bad1) goto fail1
>
> fail2:?
> ? fail2 stuff
> fail1:?
> ? ?fail1 stuff
>
>
>
> Thanks
>
> ron
>
>

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

end of thread, other threads:[~2014-06-10  6:23 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-06-09 22:04 [Cocci] replace waserror/error with goto fail ron minnich
2014-06-10  6:23 ` Julia Lawall

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.