Re: [RFC] Replacing special goto statements by direct returns?

From: Markus Elfring

Date: Tue Nov 03 2026 - 12:48:43 EST


> I think you can do:
>
> @useful@
> statement S;
> expression error;
> identifier error0;
> position p;
> @@
>
> S
> error0:@p
> return error;
>
> @useless@
> position p1 != useful.p;
> expression error;
> identifier error0;
> @@
>
> f(...) {
> (
> <...
> - goto error0;
> + return error;
> ...>
> &
> ...
> error0:@p1
> return error;
> )
> }
>
> I have not tested this.

This is a pity.


> It might not work,

I got corresponding development concerns.

* You proposed to use a statement variable in the SmPL rule “useful”.
How safe is the control flow connection to the subsequent code?

* Another metavariable declaration is probably helpful for “f” in the SmPL rule “useless”.


Questionable test result:
Markus_Elfring@Sonne:…/Projekte/Coccinelle/janitor> spatch --parse-cocci replace_goto_by_return-Julia.cocci
…
minus: parse error:
File "replace_goto_by_return-Julia.cocci", line 25, column 2, charpos = 400
around = '...',
whole content = & ...


Would you be looking for a better SmPL conjunction?


> or it might be very slow.

I hope that experiences can grow also for more desirable software run time characteristics.

Regards,
Markus