All of lore.kernel.org
 help / color / mirror / Atom feed
From: Bernhard Reutner-Fischer <rep.dot.nop@gmail.com>
To: Julia Lawall <julia.lawall@inria.fr>
Cc: rep.dot.nop@gmail.com, cocci@inria.fr
Subject: Re: [cocci] HELP: multiple inserts at one position
Date: Thu, 9 Mar 2023 10:10:01 +0100	[thread overview]
Message-ID: <20230309101001.78c0bc26@nbbrfq> (raw)
In-Reply-To: <ad666bb2-3f4-47a2-13fd-8f7e29b8af79@inria.fr>

[-- Attachment #1: Type: text/plain, Size: 1980 bytes --]

On Thu, 9 Mar 2023 09:47:17 +0100 (CET)
Julia Lawall <julia.lawall@inria.fr> wrote:

> On Thu, 9 Mar 2023, Julia Lawall wrote:

> Another issue is that your semantic patch could be more efficient.  You
> have the declaration
> 
> type mpz_t;
> 
> I think you meant:
> 
> typedef mpz_t;
> 
> Then the only goal of the pattern
> 
> mpz_t i;
> ...
> 
> seems to be to ensure the type of i.  This can be done in the metavariable
> declaration:

I initially had a typedef, but thought i'd better simplify it, so yea.

> 
> local idexpression mpz_t i

Ok, i once had a local idexpression but without the type, thanks for
the hint!

> 
> and then in the second rule, it would be:
> 
> local idexpression mpz_t mpz_0_find.i;
> 
> In this way, you will not be matching from the top of the function, but
> rather only from the relevant call to the return.

Ah, excellent, many thanks! Works marvellous as attached.

Now, mere cosmetics, but is there a way to retain the spaces before the
braces in the replacement?
That would spare me a sed to obey to the coding conventions in gcc.
With the attached i get:
$ spatch --sp-file /tmp/mpz_free.0.cocci.txt /tmp/inp.cc
diff = 
--- /tmp/inp.cc
+++ /tmp/cocci-output-1431557-e530f9-inp.cc
@@ -54,6 +54,7 @@ CompileExpr::compile_integer_literal (co
   if (mpz_init_set_str (ival, literal_value.as_string ().c_str (), 10) != 0)
     {
       rust_error_at (expr.get_locus (), "bad number in literal");
+      mpz_clear(ival);
       return error_mark_node;
     }
 
@@ -69,6 +70,8 @@ CompileExpr::compile_integer_literal (co
 		     "integer overflows the respective type %<%s%>",
 		     tyty->get_name ().c_str ());
       mpz_clears (ival, expr, NULL); /* fake, just checking.. */
+      mpz_clear(type_min);
+      mpz_clear(type_max);
       return error_mark_node;
     }
 
@@ -77,5 +80,6 @@ CompileExpr::compile_integer_literal (co
   mpz_clear (type_min);
   mpz_clear (type_max);
 
+  mpz_clear(ival);
   return result;
 }


Thanks again!

[-- Attachment #2: mpz_free.0.cocci.txt --]
[-- Type: text/plain, Size: 489 bytes --]

/// mpz ///////////////////////////////////////////////////////////////

@ mpz_0_find exists@
typedef mpz_t;
local idexpression mpz_t i;
position ret_pos;
@@
(
mpz_init_set_str (i, ...)
|
mpz_init (i)
|
mpz_init2 (i, ...)
|
mpz_init3 (i, ...)
)
... when != mpz_clear (i)
    when != mpz_clears (...,i,...)
(
  return \(<+...i...+>\);
|
return@ret_pos ...;
)

@ mpz_0_replace @
local idexpression mpz_t mpz_0_find.i;
position mpz_0_find.ret_pos;
@@
++ mpz_clear (i);
? return@ret_pos ...;


  reply	other threads:[~2023-03-09  9:39 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-03-09  8:28 [cocci] HELP: multiple inserts at one position Bernhard Reutner-Fischer
     [not found] ` <89959f1e-b5ed-6b2c-2931-4fdd65428e89@inria.fr>
2023-03-09  8:47   ` Julia Lawall
2023-03-09  9:10     ` Bernhard Reutner-Fischer [this message]
2023-03-09  9:38       ` Julia Lawall
2023-03-09 10:15         ` Bernhard Reutner-Fischer
2023-03-09 10:23           ` Julia Lawall
2023-03-10 10:01     ` Bernhard Reutner-Fischer
2023-03-10 10:12       ` Julia Lawall
2023-03-13 19:38         ` Bernhard Reutner-Fischer
2023-03-13 21:09           ` Julia Lawall

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230309101001.78c0bc26@nbbrfq \
    --to=rep.dot.nop@gmail.com \
    --cc=cocci@inria.fr \
    --cc=julia.lawall@inria.fr \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.