Skip to contentSkip to conversation

expression without side effects

Cocci Denis Efremov 2 participants 4 messages Sep 2, 2020

lore
Share & tools
lore
#0 lore raw

Hi,

I'm trying to write a pattern to match expression without side-effects, i.e expression E but not i++, --i, function call.

While trying to write it I faced that this expression matches different array indices. Actually, it's quite unexpected for me:

@@
expression E;
identifier A;
@@

* E->A || E->A

Actually, I would expect it not to match the file at all:

$ spatch --cocci-file ./test.cocci ./drivers/md/dm-clone-metadata.c
init_defs_builtins: /usr/lib64/coccinelle/standard.h
HANDLING: ./drivers/md/dm-clone-metadata.c
diff =
--- ./drivers/md/dm-clone-metadata.c
+++ /tmp/cocci-output-11041-66b4fb-dm-clone-metadata.c
@@ -947,7 +947,6 @@ bool dm_clone_changed_this_transaction(s
unsigned long flags;

spin_lock_irqsave(&cmd->bitmap_lock, flags);
- r = cmd->dmap[0].changed || cmd->dmap[1].changed;
spin_unlock_irqrestore(&cmd->bitmap_lock, flags);

return r;

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

#1 lore raw
Quoted 8 lines · Denis Efremov

Hi,

I'm trying to write a pattern to match expression without side-effects, i.e expression E but not i++, --i, function call.

While trying to write it I faced that this expression matches different array indices. Actually, it's quite unexpected for me:

Quoted 6 lines

@@
expression E;
identifier A;
@@

* E->A || E->A

There is an isomorphism that you can disable: ptr_to_array

julia

Quoted 18 lines

Actually, I would expect it not to match the file at all:

$ spatch --cocci-file ./test.cocci ./drivers/md/dm-clone-metadata.c
init_defs_builtins: /usr/lib64/coccinelle/standard.h
HANDLING: ./drivers/md/dm-clone-metadata.c
diff =
tmp/cocci-output-11041-66b4fb-dm-clone-metadata.c renamed from drivers/md/dm-clone-metadata.c +0 -1
@@ -947,7 +947,6 @@ bool dm_clone_changed_this_transaction(s
 unsigned long flags;
 
 spin_lock_irqsave(&cmd->bitmap_lock, flags);
-       r = cmd->dmap[0].changed || cmd->dmap[1].changed;
 spin_unlock_irqrestore(&cmd->bitmap_lock, flags);
 
 return r;
Quoted 7 lines

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

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

#3 lore raw
Quoted 9 lines · Denis Efremov
Quoted 1 line · Julia Lawall

There is an isomorphism that you can disable: ptr_to_array

Thanks!

Anyway, even with ptr_to_array enabled equalizing cmd->dmap[0] and cmd->dmap[1] looks incorrect to me.

Indeed, in looking at the rule, it doesn't look like this is the kind of expression that should be involved...

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