Coccinelle archive mirror
 help / color / mirror / Atom feed
From: Alyssa Rosenzweig <alyssa@rosenzweig.io>
To: cocci@inria.fr
Subject: [cocci] Replacement of the form `x |= function()`
Date: Mon, 24 Feb 2025 16:24:35 -0500	[thread overview]
Message-ID: <Z7zjkyOeoPNYeOR3@blossom> (raw)

Hi, I've hit an awkward corner case combining operators-with-assignment
with a function call in the replacement of a semantic patch.

These patches both work as expected (@@..@@ sections omitted):

    -lhs = rhs;
    +lhs |= rhs;

and

    -lhs = rhs;
    +lhs = myfunc(rhs);

However, putting it together...

    -lhs = rhs;
    +lhs |= myfunc(rhs);

...fails with a parse error

    plus: parse error:
      File "s.cocci", line 7, column 8, charpos = 59
      around = 'myfunc',
      whole content = +lhs |= myfunc(rhs);

Is this expected? Is this a Coccinelle bug, or an invalid semantic
patch? Is there a correct way to specify this replacement?

---

As a workaround, this patch does work

    -lhs = rhs;
    +lhs |= (myfunc(rhs));

..but results in superfluous parantheses in the output... which I guess
can be removed with

    -lhs = (rhs);
    +lhs = rhs;

...but this is surely not the right fix :-)

---

I use Coccinelle for collateral evolutions in Mesa3D's compiler stack.
This particular case came up when working on
https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/33722 for the
"real-world" motivation.

Thanks,

Alyssa

             reply	other threads:[~2025-02-25 20:28 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-02-24 21:24 Alyssa Rosenzweig [this message]
2025-02-25 20:33 ` [cocci] Replacement of the form `x |= function()` Julia Lawall
2025-02-25 21:05   ` Alyssa Rosenzweig
2025-02-25 21:16     ` Julia Lawall
2025-03-01 13:36   ` Markus Elfring
2025-03-01 23:44     ` Julia Lawall
2025-03-02 10:55       ` Markus Elfring
2025-03-02 12:59     ` Julia Lawall
2025-03-02 13:18       ` [cocci] Data processing challenges with “compound assignment operators”? Markus Elfring
2025-03-02 12:55 ` [cocci] Replacement of the form `x |= function()` Markus Elfring

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=Z7zjkyOeoPNYeOR3@blossom \
    --to=alyssa@rosenzweig.io \
    --cc=cocci@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).