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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
jtojnar opened this issue Jun 10, 2024 · 0 comments
Open

Question mark breaks replacement with empty block #369

jtojnar opened this issue Jun 10, 2024 · 0 comments

Comments

@jtojnar
Copy link
Contributor
jtojnar commented Jun 10, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant
0