On Wed, 14 Dec 2011, Josh Triplett wrote:

On Wed, Dec 14, 2011 at 10:56:24AM -0800, Josh Triplett wrote:
In the development of a semantic patch, I found myself writing this:

@@ struct task_struct *task; @@
- (task)->pid == 0
+ is_idle_task(task)

@@ struct task_struct *task; @@
- (task)->pid != 0
+ !is_idle_task(task)

It seems like some way should exist to only write one of those and have
coccinelle derive the other one, but I didn't manage to find it.  I'd
like to avoid the redundancy if possible; any suggestions?

Specifically, both cases work somewhat, but don't handle all code
correctly.  The first case misses some code, and the second case doesn't
produce the optimal result.  Consider the following test case:

#include <linux/sched.h>
extern struct task_struct *p;
extern struct task_struct v;
void context(void)
{
        if (p->pid)
                do_something();
        if ((&v)->pid)
                do_something();
        if (!p->pid)
                do_something();
        if (!(&v)->pid)
                do_something();
}

If I only write the first (==0) case, coccinelle manages to patch the
first, third, and fourth conditionals, but misses the second.  If I only
write the second (!=0) case, coccinelle patches all four conditionals,
but the third and fourth end up with !!is_idle_task rather than just
is_idle_task.  (Note that is_idle_task has type bool.)

I'd like to write just one of the two cases to match all four
conditionals and avoid double negatives.  Ideally, either one of the two
cases should have that result; I don't want to have to remember a magic
rule for which of those variants works correctly.

What version of Coccinelle do you have? I don't get double negatives for any of the examples.

julia
_______________________________________________
Cocci mailing list
[email protected]
http://lists.diku.dk/mailman/listinfo/cocci
(Web access from inside DIKUs LAN only)

Reply via email to