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

Kenneth Graunke kenneth at whitecape.org
Wed Dec 16 11:05:33 PST 2015


On Monday, December 14, 2015 03:34:25 PM Ian Romanick 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)
> 

Patches 1-2 are:
Reviewed-by: Kenneth Graunke <kenneth at whitecape.org>

While I believe GCC does the right thing here, I believe that relying on
{{NULL}} initializing all fields is technically relying on undefined
behavior.  It's good practice to initialize fields, and there's really
no reason not to.

True, it's annoying to have to maintain such a list when adding/changing
fields in the structure - but I expect that changing nir_src will be
pretty rare.  It hasn't changed much since it was introduced.

The right solution is to use C99 designated initializers - where
unspecified fields are actually defined to be zero-initialized - but we
can't due to MSVC 2013 bugs.  Apparently this is fixed in MSVC 2015 [1],
so when Jose lets us move to that, we can simplify this.

[1] http://stackoverflow.com/questions/24090739/possible-compiler-bug-in-msvc12-vs2013-with-designated-initializer
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: This is a digitally signed message part.
URL: <http://lists.freedesktop.org/archives/mesa-dev/attachments/20151216/56403e81/attachment.sig>


More information about the mesa-dev mailing list