Skip to contentSkip to conversation

multiple fields declaration

Cocci Nic Volanschi (R&D) 3 participants 5 messages Sep 27, 2013

lore
Share & tools
lore
#0 lore raw

Hi,

I found an unfortunate asymmetry on matching an identifier declared in a multiple declaration. In short, it works fine on a multiple variables declaration, but not on a multiple fields declaration.

For example, the following semantic patch, adding parentheses around uses of integer variables and integer fields:

--- intvar2.cocci:
@findvar@ identifier i; @@
int i;

@expression@ identifier findvar.i; @@
+(
i
+)

@findfld@ identifier id, id3; @@
struct {
...
int id;
...} id3;

@expression@ identifier x, findfld.id; @@
+(
x.id
+)

---
applied on the following program:

--- intvar2.c:
#include <stdio.h>

struct {
int f1, f2;
int f3;
} s;

int main() {
int i1, i2;
int i3;
i1 = 11;
i2 = 22;
i3 = 33;
printf("%d, %d, %d\n", i1, i2, i3);
s.f1 = 44;
s.f2 = 55;
s.f3 = 66;
printf("{%d, %d, %d}\n", s.f1, s.f2, s.f3);
}

---
transforms variables i1, i2, i3, and field f3, but not fields f1 and f2.

Is it possible to turn around this problem? Or even better, to fix it...?

Thanks,
Nic.

#1 lore raw

Hi,

It worked for me when I've removed the two ... inside the struct, like:

@findvar@ identifier i; @@
int i;

@expression@ identifier findvar.i; @@
+(
i
+)

@findfld@ identifier id, id3; @@
struct {
int id;
} id3;

@expression@ identifier x, findfld.id; @@
+(
x.id
+)

Does it work for you?

[]'s

Peter

Quoted 67 lines · Nic Volanschi (R&D)

Hi,

I found an unfortunate asymmetry on matching an identifier declared in a multiple declaration. In short, it works fine on a multiple variables declaration, but not on a multiple fields declaration.

For example, the following semantic patch, adding parentheses around uses of integer variables and integer fields:

--- intvar2.cocci:
@findvar@ identifier i; @@
int i;

@expression@ identifier findvar.i; @@

(quoted diff) +2 -0
+(
  i
+)

@findfld@ identifier id, id3; @@
struct {
...
int id;
...} id3;

@expression@ identifier x, findfld.id; @@

(quoted diff) +2 -1
+(
  x.id
+)
 
---

applied on the following program:

--- intvar2.c:
#include <stdio.h>

struct {
int f1, f2;
int f3;
} s;

int main() {
int i1, i2;
int i3;
i1 = 11;
i2 = 22;
i3 = 33;
printf("%d, %d, %d\n", i1, i2, i3);
s.f1 = 44;
s.f2 = 55;
s.f3 = 66;
printf("{%d, %d, %d}\n", s.f1, s.f2, s.f3);
}

---
transforms variables i1, i2, i3, and field f3, but not fields f1 and f2.

Is it possible to turn around this problem? Or even better, to fix it...?

Thanks,
Nic.

_______________________________________________
Cocci mailing list
Cocci at systeme.lip6.fr
https://systeme.lip6.fr/mailman/listinfo/cocci

Signature · 1 line
Peter
#2 lore raw

Hi Peter,

Thanks for the suggestion, but it does not work for me. When I take out the two "..." in the struct, in rule findfld, as you showed, it doesn't transform anymore any of the fields:

tmp/cocci-output-16102-361c4b-intvar2.c renamed from intvar2.c +4 -4
diff = 
@@ -9,10 +9,10 @@ struct {
 int main() {
   int i1, i2;
   int i3;
-  i1 = 11;
-  i2 = 22;
-  i3 = 33;
-  printf("%d, %d, %d\n", i1, i2, i3);
+  (i1) = 11;
+  (i2) = 22;
+  (i3) = 33;
+  printf("%d, %d, %d\n", (i1), (i2), (i3));
   s.f1 = 44;
   s.f2 = 55;
   s.f3 = 66;

So even f3, which got transformed with the "..."s, doesn't get transformed anymore.

Are you using a very recent update?
I tried your suggestion both in an older version (1.0.0-rc15) and in a recent one, got from the git hub last week:

nic at paquito:~/Download/coccinelle$ git show
commit 0343f05476af56a35c9a1c05f14ef544c1391a54

Author: julia <[email protected]>
Date:   Thu Sep 19 11:29:21 2013 +0200

cache-limit

changes.txt +0 -0
index 554fa1b..58391e2 100644
@@ -288,6 +288,8 @@
 - Identifiers promoted to typedefs should have positions
 - Allow disjunctions in removed nests
 - Only print a warning about multidecls if the pattern actually

matches.
+- fixed --cache-limit to set --use-cache. Thanks to Tegawende Bissyande
+ for finding the problem.

* 0.2.5
** Language:

main.ml +0 -0
index 869858b..487d08b 100644

Cheers,
Nic.

Quoted 100 lines · Peter Senna Tschudin

Hi,

It worked for me when I've removed the two ... inside the struct, like:

@findvar@ identifier i; @@
int i;

@expression@ identifier findvar.i; @@

(quoted diff) +2 -0
+(
  i
+)

@findfld@ identifier id, id3; @@
struct {
int id;
} id3;

@expression@ identifier x, findfld.id; @@

(quoted diff) +2 -0
+(
  x.id
+)

Does it work for you?

[]'s

Peter

Quoted 67 lines · Nic Volanschi (R&D)

Hi,

I found an unfortunate asymmetry on matching an identifier declared in a multiple declaration. In short, it works fine on a multiple variables declaration, but not on a multiple fields declaration.

For example, the following semantic patch, adding parentheses around uses of integer variables and integer fields:

--- intvar2.cocci:
@findvar@ identifier i; @@
int i;

@expression@ identifier findvar.i; @@

(quoted diff) +2 -0
+(
  i
+)

@findfld@ identifier id, id3; @@
struct {
...
int id;
...} id3;

@expression@ identifier x, findfld.id; @@

(quoted diff) +2 -1
+(
  x.id
+)
 
---

applied on the following program:

--- intvar2.c:
#include <stdio.h>

struct {
int f1, f2;
int f3;
} s;

int main() {
int i1, i2;
int i3;
i1 = 11;
i2 = 22;
i3 = 33;
printf("%d, %d, %d\n", i1, i2, i3);
s.f1 = 44;
s.f2 = 55;
s.f3 = 66;
printf("{%d, %d, %d}\n", s.f1, s.f2, s.f3);
}

---
transforms variables i1, i2, i3, and field f3, but not fields f1 and f2.

Is it possible to turn around this problem? Or even better, to fix it...?

Thanks,
Nic.

_______________________________________________
Cocci mailing list
Cocci at systeme.lip6.fr
https://systeme.lip6.fr/mailman/listinfo/cocci

#3 lore raw

Hi Nic,

Quoted 5 lines · Nic Volanschi (R&D)

Hi Peter,

Thanks for the suggestion, but it does not work for me. When I take out the two "..." in the struct, in rule findfld, as you showed, it doesn't transform anymore any of the fields:

Oops, actually the same happens to me. Sorry for the suggestion that do not work...

Quoted 160 lines

diff =

tmp/cocci-output-16102-361c4b-intvar2.c renamed from intvar2.c +4 -4
@@ -9,10 +9,10 @@ struct {
 int main() {
   int i1, i2;
   int i3;
-  i1 = 11;
-  i2 = 22;
-  i3 = 33;
-  printf("%d, %d, %d\n", i1, i2, i3);
+  (i1) = 11;
+  (i2) = 22;
+  (i3) = 33;
+  printf("%d, %d, %d\n", (i1), (i2), (i3));
   s.f1 = 44;
   s.f2 = 55;
   s.f3 = 66;

So even f3, which got transformed with the "..."s, doesn't get transformed anymore.

Are you using a very recent update?
I tried your suggestion both in an older version (1.0.0-rc15) and in a recent one, got from the git hub last week:

nic at paquito:~/Download/coccinelle$ git show
commit 0343f05476af56a35c9a1c05f14ef544c1391a54

Author: julia <[email protected]>
Date:   Thu Sep 19 11:29:21 2013 +0200

cache-limit

changes.txt +0 -0
index 554fa1b..58391e2 100644
@@ -288,6 +288,8 @@
 - Identifiers promoted to typedefs should have positions
 - Allow disjunctions in removed nests
 - Only print a warning about multidecls if the pattern actually

matches.
+- fixed --cache-limit to set --use-cache. Thanks to Tegawende Bissyande

changes.txt +1 -0
+  for finding the problem.
 
 * 0.2.5
 ** Language:
main.ml +0 -0
index 869858b..487d08b 100644

Cheers,
Nic.

Quoted 100 lines · Peter Senna Tschudin

Hi,

It worked for me when I've removed the two ... inside the struct, like:

@findvar@ identifier i; @@
int i;

@expression@ identifier findvar.i; @@

(quoted diff) +2 -0
+(
  i
+)

@findfld@ identifier id, id3; @@
struct {
int id;
} id3;

@expression@ identifier x, findfld.id; @@

(quoted diff) +2 -0
+(
  x.id
+)

Does it work for you?

[]'s

Peter

Quoted 67 lines · Nic Volanschi (R&D)

Hi,

I found an unfortunate asymmetry on matching an identifier declared in a multiple declaration. In short, it works fine on a multiple variables declaration, but not on a multiple fields declaration.

For example, the following semantic patch, adding parentheses around uses of integer variables and integer fields:

--- intvar2.cocci:
@findvar@ identifier i; @@
int i;

@expression@ identifier findvar.i; @@

(quoted diff) +2 -0
+(
  i
+)

@findfld@ identifier id, id3; @@
struct {
...
int id;
...} id3;

@expression@ identifier x, findfld.id; @@

(quoted diff) +2 -1
+(
  x.id
+)
 
---

applied on the following program:

--- intvar2.c:
#include <stdio.h>

struct {
int f1, f2;
int f3;
} s;

int main() {
int i1, i2;
int i3;
i1 = 11;
i2 = 22;
i3 = 33;
printf("%d, %d, %d\n", i1, i2, i3);
s.f1 = 44;
s.f2 = 55;
s.f3 = 66;
printf("{%d, %d, %d}\n", s.f1, s.f2, s.f3);
}

---
transforms variables i1, i2, i3, and field f3, but not fields f1 and f2.

Is it possible to turn around this problem? Or even better, to fix it...?

Thanks,
Nic.

_______________________________________________
Cocci mailing list
Cocci at systeme.lip6.fr
https://systeme.lip6.fr/mailman/listinfo/cocci

Signature · 1 line
Peter
#4 lore raw
In reply to Nic Volanschi (R&D)

It simply isn't planned for in the implementation.

I can fix it early next week.

julia

Quoted 170 lines · Nic Volanschi (R&D)

Hi Peter,

Thanks for the suggestion, but it does not work for me. When I take out the two "..." in the struct, in rule findfld, as you showed, it doesn't transform anymore any of the fields:

diff =

tmp/cocci-output-16102-361c4b-intvar2.c renamed from intvar2.c +4 -4
@@ -9,10 +9,10 @@ struct {
 int main() {
   int i1, i2;
   int i3;
-  i1 = 11;
-  i2 = 22;
-  i3 = 33;
-  printf("%d, %d, %d\n", i1, i2, i3);
+  (i1) = 11;
+  (i2) = 22;
+  (i3) = 33;
+  printf("%d, %d, %d\n", (i1), (i2), (i3));
   s.f1 = 44;
   s.f2 = 55;
   s.f3 = 66;

So even f3, which got transformed with the "..."s, doesn't get transformed anymore.

Are you using a very recent update?
I tried your suggestion both in an older version (1.0.0-rc15) and in a recent one, got from the git hub last week:

nic at paquito:~/Download/coccinelle$ git show
commit 0343f05476af56a35c9a1c05f14ef544c1391a54

Author: julia <[email protected]>
Date:   Thu Sep 19 11:29:21 2013 +0200

cache-limit

changes.txt +0 -0
index 554fa1b..58391e2 100644
@@ -288,6 +288,8 @@
 - Identifiers promoted to typedefs should have positions
 - Allow disjunctions in removed nests
 - Only print a warning about multidecls if the pattern actually

matches.
+- fixed --cache-limit to set --use-cache. Thanks to Tegawende Bissyande

changes.txt +1 -0
+  for finding the problem.
 
 * 0.2.5
 ** Language:
main.ml +0 -0
index 869858b..487d08b 100644

Cheers,
Nic.

Quoted 89 lines · Peter Senna Tschudin

Hi,

It worked for me when I've removed the two ... inside the struct, like:

@findvar@ identifier i; @@
int i;

@expression@ identifier findvar.i; @@

(quoted diff) +2 -0
+(
  i
+)

@findfld@ identifier id, id3; @@
struct {
int id;
} id3;

@expression@ identifier x, findfld.id; @@

(quoted diff) +2 -0
+(
  x.id
+)

Does it work for you?

[]'s

Peter

Quoted 59 lines · Nic Volanschi (R&D)

Hi,

I found an unfortunate asymmetry on matching an identifier declared in a multiple declaration. In short, it works fine on a multiple variables declaration, but not on a multiple fields declaration.

For example, the following semantic patch, adding parentheses around uses of integer variables and integer fields:

--- intvar2.cocci:
@findvar@ identifier i; @@
int i;

@expression@ identifier findvar.i; @@

(quoted diff) +2 -0
+(
  i
+)

@findfld@ identifier id, id3; @@
struct {
...
int id;
...} id3;

@expression@ identifier x, findfld.id; @@

(quoted diff) +2 -1
+(
  x.id
+)
 
---

applied on the following program:

--- intvar2.c:
#include <stdio.h>

struct {
int f1, f2;
int f3;
} s;

int main() {
int i1, i2;
int i3;
i1 = 11;
i2 = 22;
i3 = 33;
printf("%d, %d, %d\n", i1, i2, i3);
s.f1 = 44;
s.f2 = 55;
s.f3 = 66;
printf("{%d, %d, %d}\n", s.f1, s.f2, s.f3);
}

---
transforms variables i1, i2, i3, and field f3, but not fields f1 and f2.

Is it possible to turn around this problem? Or even better, to fix it...?

Quoted 11 lines
Quoted 8 lines

Thanks,
Nic.

_______________________________________________
Cocci mailing list
Cocci at systeme.lip6.fr
https://systeme.lip6.fr/mailman/listinfo/cocci

_______________________________________________
Cocci mailing list
Cocci at systeme.lip6.fr
https://systeme.lip6.fr/mailman/listinfo/cocci