[Mesa-dev] [PATCH 4/4] glsl: Fix type-checking in ast-to-hir for bitwise-not

Chad Versace chad at chad-versace.us
Thu Oct 7 16:34:48 PDT 2010


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");
 	 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);
-- 
1.7.1



More information about the mesa-dev mailing list