8000 Question mark breaks replacement with empty block · Issue #369 · coccinelle/coccinelle · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
Question mark breaks replacement with empty block #369
Open
@jtojnar

Description

@jtojnar

Applying the following semantic patch (simplified from https://gitlab.gnome.org/jtojnar/glib-refactoring/-/blob/0da312c4bfe3602cfc9d10c1e8f56b7574ad1c8a/patches/glib/autocleanup.cocci):

@@
identifier i;
@@
Foo *i;
<...
-foo(i);
...>
?\Foo *i;

To the C code below:

void fun() {
  Foo *a;

  if (a != NULL)
    foo(a);
}

produces invalid C code – the if body is removed but no empty block is inserted:

$ spatch --sp-file foo.cocci foo.c
init_defs_builtins: /nix/store/i0xir67av8vqj2f5vrgaiq0v6f7yl9b2-coccinelle-dev/lib/coccinelle/standard.h
SPECIAL NAMES: adding Foo as a type
HANDLING: foo.c
diff = 
--- foo.c
+++ /tmp/cocci-output-28593-b00f94-foo.c
@@ -2,5 +2,4 @@ void fun() {
   Foo *a;
 
   if (a != NULL)
-    foo(a);
-}
+  }

Alternately, if there is more code after the if statement, the immediately following statement will become body of the if:

--- foo.c
+++ /tmp/cocci-output-37272-626a04-foo.c
@@ -2,7 +2,6 @@ void fun() {
   Foo *a;
 
   if (a != NULL)
-    foo(a);
 
-  bar();
+    bar();
 }

Empty block is correctly inserted if the question mark line is removed:

--- foo.c
+++ /tmp/cocci-output-37350-45ac0d-foo.c
@@ -2,7 +2,7 @@ void fun() {
   Foo *a;
 
   if (a != NULL)
-    foo(a);
+    {}
 
   bar();
 }

Using coccinelle 1.2 but I can reproduce on master (ac9af0e) as well.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0