[Mesa-dev] [PATCH] nir: Silence GCC maybe-uninitialized warnings.

Matt Turner mattst88 at gmail.com
Mon Nov 2 09:51:34 PST 2015


On Mon, Nov 2, 2015 at 1:30 AM, Vinson Lee <vlee at freedesktop.org> wrote:
> nir/nir_control_flow.c: In function ‘split_block_cursor.isra.11’:
> nir/nir_control_flow.c:460:15: warning: ‘after’ may be used uninitialized in this function [-Wmaybe-uninitialized]
>        *_after = after;
>                ^
> nir/nir_control_flow.c:458:16: warning: ‘before’ may be used uninitialized in this function [-Wmaybe-uninitialized]
>        *_before = before;
>                 ^
>
> Signed-off-by: Vinson Lee <vlee at freedesktop.org>
> ---
>  src/glsl/nir/nir_control_flow.c | 3 +++
>  1 file changed, 3 insertions(+)
>
> diff --git a/src/glsl/nir/nir_control_flow.c b/src/glsl/nir/nir_control_flow.c
> index 7f51c4f..96395a4 100644
> --- a/src/glsl/nir/nir_control_flow.c
> +++ b/src/glsl/nir/nir_control_flow.c
> @@ -452,6 +452,9 @@ split_block_cursor(nir_cursor cursor,
>           before = split_block_before_instr(nir_instr_next(cursor.instr));
>        }
>        break;
> +
> +   default:
> +      unreachable("not reached");
>     }

We've avoided adding this, because it seems like an absurd warning.
The enum that's the subject of the switch has four members, all of
which are handled in the switch.

Researching this, it appears that gcc doesn't consider this warning
indicate a bug because of some combination of (1) enums in C are just
ints and can contain values not associated with an enum member, and
(2) it would apparently require extra (generated) code to ensure that
the value is that of an enum member.

I don't imagine we'll want to add more members to the enum, so maybe
it's okay...


More information about the mesa-dev mailing list