On Thu, 9 Mar 2023 09:47:17 +0100 (CET) Julia Lawall 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!