[Mesa-dev] [PATCH 1/8] nir: Silence missing field initializer warnings for nir_src

Ian Romanick idr at freedesktop.org
Mon Dec 14 16:28:45 PST 2015


On 12/14/2015 03:38 PM, Ilia Mirkin wrote:
> It's a pretty standard feature of compilers to init things to 0 and
> not have the full structure specified like that... what compiler are
> you seeing these with? Can we just fix the glitch with a
> -Wno-stupid-warnings?

I have observed this with several versions of GCC.

In C, you can avoid this with a trailing comma like:

#define NIR_SRC_INIT (nir_src) { { NULL }, }

However, nir.h is also used in some C++ code where that doesn't help.

To be honest, I'm not a big fan of these macros.  Without C99 designated
initalizers, maintaining initializers like these (or the ones in
src/glsl/builtin_variables.cpp) is a real pain.  We can't use those, and
we can't use C++ constructors.  We have no good options available. :(

I thought about replacing them with a static inline function that
returns a zero-initialized struct.  The compiler should generate the
same code.  However, that doesn't work with uses like those in patch 3.

I'm also a little curious why you didn't raise this issue when I sent
these patches out in August.  I removed the patch from the series that
you objected to back then.

> On Mon, Dec 14, 2015 at 6:34 PM, Ian Romanick <idr at freedesktop.org> wrote:
>> From: Ian Romanick <ian.d.romanick at intel.com>
>>
>> nir/nir.h: In function 'nir_src_for_ssa':
>> nir/nir.h:552:4: warning: missing initializer for field 'use_link' of 'nir_src'
>> [-Wmissing-field-initializers]
>>     nir_src src = NIR_SRC_INIT;
>>     ^
>> In file included from nir/nir.c:28:0:
>> nir/nir.h:508:21: note: 'use_link' declared here
>>     struct list_head use_link;
>>                      ^
>>
>> Number of total warnings in my build reduced from 2329 to 1932
>> (reduction of 397).
>>
>> Signed-off-by: Ian Romanick <ian.d.romanick at intel.com>
>> ---
>>  src/glsl/nir/nir.h | 2 +-
>>  1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/src/glsl/nir/nir.h b/src/glsl/nir/nir.h
>> index 2e72e66..5543c52 100644
>> --- a/src/glsl/nir/nir.h
>> +++ b/src/glsl/nir/nir.h
>> @@ -515,7 +515,7 @@ typedef struct nir_src {
>>     bool is_ssa;
>>  } nir_src;
>>
>> -#define NIR_SRC_INIT (nir_src) { { NULL } }
>> +#define NIR_SRC_INIT (nir_src) { { NULL }, { NULL, NULL }, { { NULL, NULL, 0 } }, false }
>>
>>  #define nir_foreach_use(reg_or_ssa_def, src) \
>>     list_for_each_entry(nir_src, src, &(reg_or_ssa_def)->uses, use_link)
>> --
>> 2.5.0
>>
>> _______________________________________________
>> mesa-dev mailing list
>> mesa-dev at lists.freedesktop.org
>> http://lists.freedesktop.org/mailman/listinfo/mesa-dev
> 



More information about the mesa-dev mailing list