[Mesa-dev] [PATCH 3/3] i965: Mark default case of type_sz() unreachable.

Emil Velikov emil.l.velikov at gmail.com
Fri Jul 17 14:09:34 PDT 2015


On 15/07/15 17:00, Matt Turner wrote:
> Otherwise Coverity thinks we'll divide by zero.
> ---
>  src/mesa/drivers/dri/i965/brw_reg.h | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/src/mesa/drivers/dri/i965/brw_reg.h b/src/mesa/drivers/dri/i965/brw_reg.h
> index c8b1341..f96b28d 100644
> --- a/src/mesa/drivers/dri/i965/brw_reg.h
> +++ b/src/mesa/drivers/dri/i965/brw_reg.h
> @@ -283,7 +283,7 @@ type_sz(unsigned type)
>     case BRW_REGISTER_TYPE_B:
>        return 1;
>     default:
> -      return 0;
> +      unreachable("not reached");
I've seen a case in nir, where a default statement + unreachable was
added, despite that every value of the enum explicitly being handled.

While I'm not sure if that's the case here, wouldn't it be better to
omit the default statement in such cases and let the compiler warn us as
new values get added ?

-Emil



More information about the mesa-dev mailing list