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

Jason Ekstrand jason at jlekstrand.net
Wed Dec 16 14:28:22 PST 2015


On Wed, Dec 16, 2015 at 11:12 AM, Kenneth Graunke <kenneth at whitecape.org> wrote:
> On Monday, December 14, 2015 03:34:27 PM Ian Romanick wrote:
>> From: Ian Romanick <ian.d.romanick at intel.com>
>>
>> nir/nir_builder.h:234:4: warning: missing initializer for field 'use_link' of 'n
>> ir_src' [-Wmissing-field-initializers]
>>     nir_alu_src alu_src = { NIR_SRC_INIT };
>>     ^
>>
>> Number of total warnings in my build reduced from 1676 to 1643
>> (reduction of 33).
>>
>> Patch generated by:
>>
>>     egrep -lr 'nir_alu_src .* = \{ NIR_SRC_INIT \}' src/ | while read f
>>     do
>>         sed --in-place -e 's/nir_alu_src \(.*\) = { NIR_SRC_INIT }/nir_alu_src \1 = { NIR_SRC_INIT, false, false, { 0, } }/' $f
>>     done
>>
>> Signed-off-by: Ian Romanick <ian.d.romanick at intel.com>
>
> I don't like this patch - it makes you type a bunch of gook every time
> you want to create a nir_alu_src.
>
> I would rather see:
>
> #define NIR_ALU_SRC_INIT { NIR_SRC_INIT, false, false, { 0, 0, 0, 0 } }
>
> and then the rest of the code changed to:
>
>    nir_alu_src alu_src = NIR_ALU_SRC_INIT;
>
> That way, it's easy to construct nir_alu_src objects.

I agree.  If we're going to go through the effort to initialize all
the members, having an INIT #define would be good.  At the time, we
weren't and putting NIR_SRC_INIT in braces wasn't too messy so I
didn't see a real need.  Adding a NIR_ALU_SRC_INIT as per above would
also get my R-B.

> (This also explicitly initializes all four elements of swizzle[4],
> because after the discussion about trailing commas in this thread,
> I'm paranoid about what works where...)
>
> That patch would get my Reviewed-by.
>
>> ---
>>  src/glsl/nir/nir_builder.h     | 4 ++--
>>  src/glsl/nir/nir_search.c      | 2 +-
>>  src/mesa/program/prog_to_nir.c | 4 ++--
>>  3 files changed, 5 insertions(+), 5 deletions(-)
>>
>> diff --git a/src/glsl/nir/nir_builder.h b/src/glsl/nir/nir_builder.h
>> index b909f483..2a68883 100644
>> --- a/src/glsl/nir/nir_builder.h
>> +++ b/src/glsl/nir/nir_builder.h
>> @@ -240,7 +240,7 @@ static inline nir_ssa_def *
>>  nir_swizzle(nir_builder *build, nir_ssa_def *src, unsigned swiz[4],
>>              unsigned num_components, bool use_fmov)
>>  {
>> -   nir_alu_src alu_src = { NIR_SRC_INIT };
>> +   nir_alu_src alu_src = { NIR_SRC_INIT, false, false, { 0, } };
>>     alu_src.src = nir_src_for_ssa(src);
>>     for (unsigned i = 0; i < num_components; i++)
>>        alu_src.swizzle[i] = swiz[i];
>> @@ -268,7 +268,7 @@ nir_ssa_for_src(nir_builder *build, nir_src src, int num_components)
>>     if (src.is_ssa && src.ssa->num_components == num_components)
>>        return src.ssa;
>>
>> -   nir_alu_src alu = { NIR_SRC_INIT };
>> +   nir_alu_src alu = { NIR_SRC_INIT, false, false, { 0, } };
>>     alu.src = src;
>>     for (int j = 0; j < 4; j++)
>>        alu.swizzle[j] = j;
>> diff --git a/src/glsl/nir/nir_search.c b/src/glsl/nir/nir_search.c
>> index 56d7e81..ab8a7d6 100644
>> --- a/src/glsl/nir/nir_search.c
>> +++ b/src/glsl/nir/nir_search.c
>> @@ -289,7 +289,7 @@ construct_value(const nir_search_value *value, nir_alu_type type,
>>        const nir_search_variable *var = nir_search_value_as_variable(value);
>>        assert(state->variables_seen & (1 << var->variable));
>>
>> -      nir_alu_src val = { NIR_SRC_INIT };
>> +      nir_alu_src val = { NIR_SRC_INIT, false, false, { 0, } };
>>        nir_alu_src_copy(&val, &state->variables[var->variable], mem_ctx);
>>
>>        assert(!var->is_constant);
>> diff --git a/src/mesa/program/prog_to_nir.c b/src/mesa/program/prog_to_nir.c
>> index 539e3c0..c5d5687 100644
>> --- a/src/mesa/program/prog_to_nir.c
>> +++ b/src/mesa/program/prog_to_nir.c
>> @@ -183,7 +183,7 @@ ptn_get_src(struct ptn_compile *c, const struct prog_src_register *prog_src)
>>           if (prog_src->RelAddr) {
>>              deref_arr->deref_array_type = nir_deref_array_type_indirect;
>>
>> -            nir_alu_src addr_src = { NIR_SRC_INIT };
>> +            nir_alu_src addr_src = { NIR_SRC_INIT, false, false, { 0, } };
>>              addr_src.src = nir_src_for_reg(c->addr_reg);
>>              nir_ssa_def *reladdr = nir_imov_alu(b, addr_src, 1);
>>
>> @@ -936,7 +936,7 @@ ptn_add_output_stores(struct ptn_compile *c)
>>            * a vec4 with undefined .xyw components.  We resolve it to a scalar, to
>>            * match GLSL's gl_FragDepth and the expectations of most backends.
>>            */
>> -         nir_alu_src alu_src = { NIR_SRC_INIT };
>> +         nir_alu_src alu_src = { NIR_SRC_INIT, false, false, { 0, } };
>>           alu_src.src = nir_src_for_reg(c->output_regs[FRAG_RESULT_DEPTH]);
>>           alu_src.swizzle[0] = SWIZZLE_Z;
>>           store->src[0] = nir_src_for_ssa(nir_fmov_alu(b, alu_src, 1));
>>
>
> _______________________________________________
> 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