[Mesa-dev] [PATCH 4/4] glsl: Fix type-checking in ast-to-hir for bitwise-not
Ian Romanick
idr at freedesktop.org
Thu Oct 7 17:50:20 PDT 2010
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Chad Versace wrote:
> From: Chad Versace <chad at chad-versace.us>
>
> In GLSL 1.30, the operand of bitwise-not can be of type int, uint, ivecN, or
> uvecN. Previously, the ast-to-hir conversion for bitwise-not only accepted
> types int and uint. This commits adds acceptance for ivecN and uvecN.
> ---
> src/glsl/ast_to_hir.cpp | 17 +++++++++++++----
> 1 files changed, 13 insertions(+), 4 deletions(-)
>
> diff --git a/src/glsl/ast_to_hir.cpp b/src/glsl/ast_to_hir.cpp
> index 0cbb431..cfedc8d 100644
> --- a/src/glsl/ast_to_hir.cpp
> +++ b/src/glsl/ast_to_hir.cpp
> @@ -849,7 +849,7 @@ ast_expression::hir(exec_list *instructions,
> error_emitted = op[0]->type->is_error() || op[1]->type->is_error();
> break;
>
> - case ast_bit_not:
> + case ast_bit_not: {
> op[0] = this->subexpressions[0]->hir(instructions, state);
>
> if (state->language_version < 130) {
> @@ -857,14 +857,23 @@ ast_expression::hir(exec_list *instructions,
> error_emitted = true;
> }
>
> - if (!op[0]->type->is_integer()) {
> - _mesa_glsl_error(&loc, state, "operand of `~' must be an integer");
> + // Reference
> + // ---------
> + // GLSL 1.30 Specification, Section 5.9, page 49
> + //
> + // The one's complement operator (~). The operand must be of type signed or
> + // unsigned integer or integer vector, [...].
> + const glsl_type * op_type = op[0]->type;
> + if (not (op_type->is_integer() or op_type->is_integer_vector())) {
> + _mesa_glsl_error(&loc, state,
> + "operand of `~' must be an integer or integer vector");
Changing the error message is fine, but is_integer actually checks that
the base type is an integral (signed or unsigned) type. This will match
all of the ivec and uvec types.
For consistency, quotations of the GLSL spec, which are a good idea,
should match the format of other spec quotations in the code. It makes
it easier to search through the code. Grep for "GLSL 1... spec" for
some examples.
> error_emitted = true;
> }
>
> - type = op[0]->type;
> + type = op_type;
> result = new(ctx) ir_expression(ir_unop_bit_not, type, op[0], NULL);
> break;
> + }
>
> case ast_logic_and: {
> op[0] = this->subexpressions[0]->hir(instructions, state);
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/
iEYEARECAAYFAkyuasoACgkQX1gOwKyEAw908gCfS5kRxkDotS/c/es5YWbipjpp
aSgAn1OW3z79AMaTw3cpE4YwpTTPBW/E
=UJ83
-----END PGP SIGNATURE-----
More information about the mesa-dev
mailing list