[Mesa-dev] [PATCH] i965: Use a ZERO() macro to initialize GENX_* structs.

Matt Turner mattst88 at gmail.com
Fri Jul 14 19:41:44 UTC 2017


On Fri, Jul 14, 2017 at 12:27 PM, Rafael Antognolli
<rafael.antognolli at intel.com> wrote:
> On Fri, Jul 14, 2017 at 12:13:59PM -0700, Matt Turner wrote:
>> On Fri, Jul 14, 2017 at 11:15 AM, Rafael Antognolli
>> <rafael.antognolli at intel.com> wrote:
>> > gen4 have commands which start with KernelStartPointer, which is a
>> > struct, so if we initialize it struct = { 0 }, we get warnings on some
>> > compilers.
>>
>> Which compilers?
>>
>> >
>> > This macro works around that and will silent such warnings.
>>
>> s/silent/silence/
>>
>> >
>> > Signed-off-by: Rafael Antognolli <rafael.antognolli at intel.com>
>> > Cc: Jason Ekstrand <jason at jlekstrand.net>
>> > ---
>> >  src/mesa/drivers/dri/i965/genX_state_upload.c | 4 +++-
>> >  1 file changed, 3 insertions(+), 1 deletion(-)
>> >
>> > diff --git a/src/mesa/drivers/dri/i965/genX_state_upload.c b/src/mesa/drivers/dri/i965/genX_state_upload.c
>> > index 54a547c..7340ed2 100644
>> > --- a/src/mesa/drivers/dri/i965/genX_state_upload.c
>> > +++ b/src/mesa/drivers/dri/i965/genX_state_upload.c
>> > @@ -205,8 +205,10 @@ KSP(struct brw_context *brw, uint32_t offset)
>> >        _dw + 1; /* Array starts at dw[1] */             \
>> >     })
>> >
>> > +#define ZERO(T) ({ T tmp; memset(&tmp, 0, sizeof(tmp)); tmp; })
>> > +
>> >  #define brw_state_emit(brw, cmd, align, offset, name)              \
>> > -   for (struct cmd name = { 0, },                                  \
>> > +   for (struct cmd name = ZERO(struct cmd),                        \
>>
>> Why don't we just use the GNU C extension {}? Clang supports it.
>>
>> That would get my
>>
>> Reviewed-by: Matt Turner <mattst88 at gmail.com>
>
> Oh, I got the idea from the IRC discussion that we didn't want to use that
> because of some options that could enable warnings for it. But I'm fine with
> it too.

I've only seen warnings about {} when using gcc's -pedantic and
clang's -Wgnu-empty-initializer (whose only purpose is to warn about
{}). I think it's safe, given that this is C (C++ has other weirdness)
and will not be compiled with MSVC.


More information about the mesa-dev mailing list