[Mesa-dev] [RFC PATCH 3/4] ff_fragment_shader: mark impossible switch values with unreachable

Nicolai Hähnle nhaehnle at gmail.com
Sat Apr 22 09:45:12 UTC 2017


On 22.04.2017 09:52, Giuseppe Bilotta wrote:
> Signed-off-by: Giuseppe Bilotta <giuseppe.bilotta at gmail.com>
> ---
>  src/mesa/main/ff_fragment_shader.cpp | 18 +++++++-----------
>  1 file changed, 7 insertions(+), 11 deletions(-)
>
> diff --git a/src/mesa/main/ff_fragment_shader.cpp b/src/mesa/main/ff_fragment_shader.cpp
> index aac9de78ca..4f2d6b07a2 100644
> --- a/src/mesa/main/ff_fragment_shader.cpp
> +++ b/src/mesa/main/ff_fragment_shader.cpp
> @@ -138,8 +138,7 @@ need_saturate( GLuint mode )
>     case TEXENV_MODE_ADD_PRODUCTS_SIGNED_NV:
>        return GL_TRUE;
>     default:
> -      assert(0);
> -      return GL_FALSE;
> +      unreachable("Invalid TexEnv Combine mode");
>     }
>  }
>
> @@ -426,8 +425,7 @@ get_source(texenv_fragment_program *p,
>        }
>
>     default:
> -      assert(0);
> -      return NULL;
> +      unreachable("Invalid TexEnv source");
>     }
>  }
>
> @@ -458,8 +456,7 @@ emit_combine_source(texenv_fragment_program *p,
>        return src;
>
>     default:
> -      assert(0);
> -      return src;
> +      unreachable("Invalid TexEnv Combine operand");
>     }
>  }
>
> @@ -495,8 +492,8 @@ static GLboolean args_match( const struct state_key *key, GLuint unit )
>  	    return GL_FALSE;
>  	 }
>  	 break;
> -      default:
> -	 return GL_FALSE;	/* impossible */
> +      default:
> +	 unreachable("Invalid TexEnv Combine operand");

For this one, I think despite the comment it'd be best to change that to 
an assert + return first, and re-visit it after some time.

Cheers,
Nicolai


>        }
>     }
>
> @@ -579,9 +576,8 @@ emit_combine(texenv_fragment_program *p,
>     case TEXENV_MODE_ADD_PRODUCTS_SIGNED_NV:
>        return add(add(mul(src[0], src[1]), mul(src[2], src[3])),
>  		 new(p->mem_ctx) ir_constant(-0.5f));
> -   default:
> -      assert(0);
> -      return src[0];
> +   default:
> +      unreachable("Invalid TexEnv Combine mode");
>     }
>  }
>
>


-- 
Lerne, wie die Welt wirklich ist,
Aber vergiss niemals, wie sie sein sollte.


More information about the mesa-dev mailing list