From: Jacob Keller <jacob.e.keller@intel.com>
To: Markus Elfring <Markus.Elfring@web.de>, <cocci@inria.fr>
Cc: Przemek Kitszel <przemyslaw.kitszel@intel.com>
Subject: Re: [cocci] behavior change in semantic patches since c36b51ffc889 …
Date: Mon, 10 Mar 2025 11:34:39 -0700 [thread overview]
Message-ID: <f85188bf-8f0d-4531-b5e7-b7bf30bedb58@intel.com> (raw)
In-Reply-To: <fdf1c4b6-9f0d-4c27-a668-65cc5926ab3d@web.de>
On 3/8/2025 1:07 AM, Markus Elfring wrote:
>> For what its worth, I was finally able to get things working pretty much
>> the same as before with the following semantic patches:
>
> This is a nice feedback.
>
>
>>> @@
>>> expression hw;
>>> @@
>>> -ice_free
>>> +devm_kfree
>>> (
>>> +ice_hw_to_dev(
>>> hw
>>> +)
>>> , ...)
>
> Did you observe that the omission of a semicolon at the end
> triggered desirable effects?
>
I'm not sure if that impacted things, but it may have.
>
>
>> and
>>
>>> @disable drop_cast@
>>> void * void_ptr;
>>> type T;
>>> @@
>>> -(T *)void_ptr
>>> +void_ptr
>
> Would another SmPL code variant be occasionally helpful?
>
> -(T *)
> void_ptr
>
I tried this version. The big issue here is that spatch will remove the
typecast, but tries to leave any code outside of -/+ alone. This results
in the types remaining on their old line when code is formatted like this:
var = (cast)
value;
This is sometimes done to avoid line length issues. With the style I
used, we get:
var = value;
But with the style you propose here we get:
var =
value;
Which is not always desirable.
I found that both styles can be helpful depending on what you're doing.
>
> Are there cases to consider where casts should be preserved?
>
Yes, I ran into this exact issue with this aggressive version because
there are some casts which do something like cast a void pointer with
immediate access, without saving it to a variable. This more aggressive
version ended up triggering on these.
We managed to get one that works with a little more context:
@disable drop_cast@
void * void_ptr;
type T;
T * typed_ptr;
@@
typed_ptr =
-(T *)void_ptr
+void_ptr
This version puts the typed_ptr as just context. This change alone seems
to be sufficient to get coccinelle to work with both versions, while
still preserving the line transformations we desired as I mentioned above.
There were exactly 2 places in the code base where this produced
different results, with the form:
type var =
(cast)value;
Because the "type var" is in a context line, it doesn't get changed and
squashed with the value.
We just modified these two places to put the cast on the first line so
it would get squashed appropriately.
> Regards,
> Markus
next prev parent reply other threads:[~2025-03-10 18:34 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-03-07 0:43 [cocci] behavior change in semantic patches since c36b51ffc889 ("don't drop down on single statement") Jacob Keller
2025-03-07 0:55 ` Julia Lawall
2025-03-07 20:24 ` Jacob Keller
2025-03-07 10:47 ` [cocci] behavior change in semantic patches since c36b51ffc889 … Markus Elfring
2025-03-07 20:53 ` Jacob Keller
2025-03-07 22:47 ` Jacob Keller
2025-03-08 9:07 ` Markus Elfring
2025-03-10 18:34 ` Jacob Keller [this message]
2025-03-11 9:10 ` Markus Elfring
2025-03-08 8:39 ` Markus Elfring
2025-03-10 18:27 ` Jacob Keller
2025-03-11 9:26 ` Przemek Kitszel
2025-03-08 9:45 ` [cocci] Evolution of transformation processes? Markus Elfring
2025-03-10 18:23 ` Jacob Keller
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=f85188bf-8f0d-4531-b5e7-b7bf30bedb58@intel.com \
--to=jacob.e.keller@intel.com \
--cc=Markus.Elfring@web.de \
--cc=cocci@inria.fr \
--cc=przemyslaw.kitszel@intel.com \
/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