Skip to contentSkip to conversation

coccinelle: misc: restrict patch mode in flexible_array.cocci

PATCH Applied Denis Efremov 2 participants 3 messages Mar 8, 2021 – Mar 24, 2021 Coccinelle/Semantic Patches (SmPL)

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 coccinelle: misc: restrict patch mode in flexible_array.cocci

Skip patches generation for structs/unions with a single field. Changing a zero-length array to a flexible array member in a struct with no named members breaks the compilation. However, reporting such cases is still valuable, e.g. commit 637464c59e0b ("ACPI: NFIT: Fix flexible_array.cocci warnings").

---
 scripts/coccinelle/misc/flexible_array.cocci | 23 ++++++++++++++++++--
 1 file changed, 21 insertions(+), 2 deletions(-)
scripts/coccinelle/misc/flexible_array.cocci +21 -2
index 947fbaff82a9..f427fd68ed2d 100644
@@ -51,21 +51,40 @@ position p : script:python() { relevant(p) };
   };
 )
 
+@only_field depends on patch@
+identifier name, array;
+type T;
+position q;
+@@
+
+(
+  struct name {@q
+    T array[0];
+  };
+|
+  struct {@q
+    T array[0];
+  };
+)
+
 @depends on patch@
 identifier name, array;
 type T;
 position p : script:python() { relevant(p) };
+// position @q with rule "only_field" simplifies
+// handling of bitfields, arrays, etc.
+position q != only_field.q;
 @@
 
 (
-  struct name {
+  struct name {@q
     ...
     T array@p[
 -       0
     ];
   };
 |
-  struct {
+  struct {@q
     ...
     T array@p[
 -       0
Signature · 6 lines
2.26.2

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

Ping?

Quoted 59 lines · Denis Efremov

Skip patches generation for structs/unions with a single field. Changing a zero-length array to a flexible array member in a struct with no named members breaks the compilation. However, reporting such cases is still valuable, e.g. commit 637464c59e0b ("ACPI: NFIT: Fix flexible_array.cocci warnings").

---
 scripts/coccinelle/misc/flexible_array.cocci | 23 ++++++++++++++++++--
 1 file changed, 21 insertions(+), 2 deletions(-)
scripts/coccinelle/misc/flexible_array.cocci +21 -2
index 947fbaff82a9..f427fd68ed2d 100644
@@ -51,21 +51,40 @@ position p : script:python() { relevant(p) };
   };
 )
 
+@only_field depends on patch@
+identifier name, array;
+type T;
+position q;
+@@
+
+(
+  struct name {@q
+    T array[0];
+  };
+|
+  struct {@q
+    T array[0];
+  };
+)
+
 @depends on patch@
 identifier name, array;
 type T;
 position p : script:python() { relevant(p) };
+// position @q with rule "only_field" simplifies
+// handling of bitfields, arrays, etc.
+position q != only_field.q;
 @@
 
 (
-  struct name {
+  struct name {@q
...
     T array@p[
 -       0
     ];
   };
 |
-  struct {
+  struct {@q
...
     T array@p[
 -       0
maintainer Applied
#2 lore raw
In reply to Denis Efremov
Quoted 7 lines · Denis Efremov

Skip patches generation for structs/unions with a single field. Changing a zero-length array to a flexible array member in a struct with no named members breaks the compilation. However, reporting such cases is still valuable, e.g. commit 637464c59e0b ("ACPI: NFIT: Fix flexible_array.cocci warnings").

Applied. I changed the log message to remove "/unions", since the change doesn't mention unions.

julia

Quoted 52 lines
---
 scripts/coccinelle/misc/flexible_array.cocci | 23 ++++++++++++++++++--
 1 file changed, 21 insertions(+), 2 deletions(-)
scripts/coccinelle/misc/flexible_array.cocci +21 -3
index 947fbaff82a9..f427fd68ed2d 100644
@@ -51,21 +51,40 @@ position p : script:python() { relevant(p) };
   };
 )
 
+@only_field depends on patch@
+identifier name, array;
+type T;
+position q;
+@@
+
+(
+  struct name {@q
+    T array[0];
+  };
+|
+  struct {@q
+    T array[0];
+  };
+)
+
 @depends on patch@
 identifier name, array;
 type T;
 position p : script:python() { relevant(p) };
+// position @q with rule "only_field" simplifies
+// handling of bitfields, arrays, etc.
+position q != only_field.q;
 @@
 
 (
-  struct name {
+  struct name {@q
...
     T array@p[
 -       0
     ];
   };
 |
-  struct {
+  struct {@q
...
     T array@p[
 -       0
--
Quoted 3 lines

2.26.2

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