From: Markus Armbruster <armbru@redhat.com>
To: "Philippe Mathieu-Daudé" <philmd@redhat.com>
Cc: Peter Maydell <peter.maydell@linaro.org>,
Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>,
qemu-devel@nongnu.org, Paolo Bonzini <pbonzini@redhat.com>
Subject: Re: Function-like macro with the same name as a typedef confuses Coccinelle
Date: Thu, 02 Apr 2020 15:47:12 +0200 [thread overview]
Message-ID: <871rp63spr.fsf@dusky.pond.sub.org> (raw)
In-Reply-To: <31eed279-5ef9-4d11-62de-51c0eeaff589@redhat.com> ("Philippe Mathieu-Daudé"'s message of "Thu, 2 Apr 2020 14:29:58 +0200")
Philippe Mathieu-Daudé <philmd@redhat.com> writes:
> On 4/2/20 2:06 PM, Markus Armbruster wrote:
>> I discovered that Vladimir's auto-propagated-errp.cocci leaves
>> hw/arm/armsse.c unchanged, even though it clearly should change it.
>> Running spatch with --debug prints (among lots of other things)
>>
>> let's go
>> -----------------------------------------------------------------------
>> -----------------------------------------------------------------------
>> parse error
>> = error in hw/arm/armsse.c; set verbose_parsing for more info
>> badcount: 7
>> bad: }
>> bad:
>> bad: static void nsccfg_handler(void *opaque, int n, int level)
>> bad: {
>> BAD:!!!!! ARMSSE *s = ARMSSE(opaque);
>> bad:
>> bad: s->nsccfg = level;
>> bad: }
>> parse error
>>
>> Alright, what's wrong with this? ARMSSE is both a function-like macro
>> and a typedef:
>>
>> #define ARMSSE(obj) OBJECT_CHECK(ARMSSE, (obj), TYPE_ARMSSE)
>>
>> typedef struct ARMSSE {
>> ...
>> } ARMSSE;
>>
>> This appears to spook Coccinelle badly enough to skip code using ARMSSE.
>>
>> If I rename the macro to ARMSSE_() just for testing, it produces the
>> transformation I'd expect.
>>
>> Grepping for typedef names is bothersome, so I used ctags -x to build a
>> cross reference table, and searched that for function-like macros
>> clashing with typedefs. Result:
>>
>> include/hw/arm/armsse.h:#define ARMSSE(obj) OBJECT_CHECK(ARMSSE, (obj), TYPE_ARMSSE)
>> include/hw/arm/armsse.h:} ARMSSE;
>> include/hw/block/swim.h:#define SWIM(obj) OBJECT_CHECK(SWIM, (obj), TYPE_SWIM)
>> include/hw/block/swim.h:} SWIM;
>> target/rx/cpu-qom.h:#define RXCPU(obj) \
>> target/rx/cpu.h:typedef struct RXCPU RXCPU;
>> target/s390x/translate.c:#define BD(N, BB, BD) { BB, 4, 0, FLD_C_b##N, FLD_O_b##N }, \
>> hw/audio/ac97.c:} BD;
>>
>> The last one is a name clash in unrelated files; should not bother
>> Coccinelle.
>>
>> The first three are due to QOM. By convention, the name of the
>> function-like macro to convert to the QOM type is the QOM type in
>> ALL_CAPS. Clash when the QOM type is ALL_CAPS already.
>
> To add to this list, another problem I'm having is with QOM interfaces.
>
> For example this line:
>
> isa_bus_dma(bus, ISADMA(isa1), ISADMA(isa2));
>
> The definitions are:
>
> #define ISADMA(obj) INTERFACE_CHECK(IsaDma, (obj), TYPE_ISADMA)
> typedef struct IsaDma IsaDma;
>
> This is used as opaque pointer, so it compiles fine, but coccinelle is
> confused because the actual 'struct IsaDma' is never defined.
Can you give me an example where Coccinelle gets confused by it?
> The only 'documentation' I found about this is commit 00ed3da9b5 which
> describes this as 'common practice'.
We discussed this in the thread
Subject: Issues around TYPE_INTERFACE
To: qemu-devel@nongnu.org
Date: Tue, 12 Mar 2019 11:50:54 +0100
Message-ID: <87h8c82woh.fsf@dusky.pond.sub.org>
Perhaps start with Paolo's reply:
Message-ID: <fdaa779c-ed79-647b-6038-3df2353fe502@redhat.com>
https://lists.nongnu.org/archive/html/qemu-devel/2019-04/msg00749.html
I just suggested to have a future docs/devel/qom.rst cover the topic:
Subject: Re: [PATCH v4 2/3] mac_via: fix incorrect creation of mos6522 device in mac_via
Message-ID: <87369m3t18.fsf@dusky.pond.sub.org>
prev parent reply other threads:[~2020-04-02 13:52 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-04-02 12:06 Function-like macro with the same name as a typedef confuses Coccinelle Markus Armbruster
2020-04-02 12:21 ` Peter Maydell
2020-04-02 13:30 ` Markus Armbruster
2020-04-07 11:58 ` Markus Armbruster
2020-04-07 13:47 ` Eric Blake
2020-04-02 12:29 ` Philippe Mathieu-Daudé
2020-04-02 13:47 ` Markus Armbruster [this message]
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=871rp63spr.fsf@dusky.pond.sub.org \
--to=armbru@redhat.com \
--cc=pbonzini@redhat.com \
--cc=peter.maydell@linaro.org \
--cc=philmd@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=vsementsov@virtuozzo.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 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.