Mesa (7.9): glsl: Ensure that equality comparisons don' t return a NULL IR tree

Ian Romanick idr at kemper.freedesktop.org
Fri Dec 17 02:21:28 UTC 2010


Module: Mesa
Branch: 7.9
Commit: d9d4f22e656f084e555e468bcf2ba465347bf5c8
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=d9d4f22e656f084e555e468bcf2ba465347bf5c8

Author: Ian Romanick <ian.d.romanick at intel.com>
Date:   Thu Dec  2 12:17:36 2010 -0800

glsl: Ensure that equality comparisons don't return a NULL IR tree

This fixes bugzilla #32035 and piglit test case array-compare-01 and
array-compare-02.

NOTE: This is a candidate for the 7.9 branch.
(cherry picked from commit 6d36be508ff0765beb6cf6bb95a323ff01e458dd)

---

 src/glsl/ast_to_hir.cpp |   35 +++++++++++++++++++----------------
 1 files changed, 19 insertions(+), 16 deletions(-)

diff --git a/src/glsl/ast_to_hir.cpp b/src/glsl/ast_to_hir.cpp
index 3bc9530..3e9a4db 100644
--- a/src/glsl/ast_to_hir.cpp
+++ b/src/glsl/ast_to_hir.cpp
@@ -629,6 +629,7 @@ static ir_rvalue *
 do_comparison(void *mem_ctx, int operation, ir_rvalue *op0, ir_rvalue *op1)
 {
    int join_op;
+   ir_rvalue *cmp = NULL;
 
    if (operation == ir_binop_all_equal)
       join_op = ir_binop_logic_and;
@@ -643,8 +644,6 @@ do_comparison(void *mem_ctx, int operation, ir_rvalue *op0, ir_rvalue *op1)
       return new(mem_ctx) ir_expression(operation, op0, op1);
 
    case GLSL_TYPE_ARRAY: {
-      ir_rvalue *last = NULL;
-
       for (unsigned int i = 0; i < op0->type->length; i++) {
 	 ir_rvalue *e0, *e1, *result;
 
@@ -654,22 +653,19 @@ do_comparison(void *mem_ctx, int operation, ir_rvalue *op0, ir_rvalue *op1)
 						new(mem_ctx) ir_constant(i));
 	 result = do_comparison(mem_ctx, operation, e0, e1);
 
-	 if (last) {
-	    last = new(mem_ctx) ir_expression(join_op, last, result);
+	 if (cmp) {
+	    cmp = new(mem_ctx) ir_expression(join_op, cmp, result);
 	 } else {
-	    last = result;
+	    cmp = result;
 	 }
       }
 
       mark_whole_array_access(op0);
       mark_whole_array_access(op1);
-
-      return last;
+      break;
    }
 
    case GLSL_TYPE_STRUCT: {
-      ir_rvalue *last = NULL;
-
       for (unsigned int i = 0; i < op0->type->length; i++) {
 	 ir_rvalue *e0, *e1, *result;
 	 const char *field_name = op0->type->fields.structure[i].name;
@@ -680,13 +676,13 @@ do_comparison(void *mem_ctx, int operation, ir_rvalue *op0, ir_rvalue *op1)
 						 field_name);
 	 result = do_comparison(mem_ctx, operation, e0, e1);
 
-	 if (last) {
-	    last = new(mem_ctx) ir_expression(join_op, last, result);
+	 if (cmp) {
+	    cmp = new(mem_ctx) ir_expression(join_op, cmp, result);
 	 } else {
-	    last = result;
+	    cmp = result;
 	 }
       }
-      return last;
+      break;
    }
 
    case GLSL_TYPE_ERROR:
@@ -695,10 +691,17 @@ do_comparison(void *mem_ctx, int operation, ir_rvalue *op0, ir_rvalue *op1)
       /* I assume a comparison of a struct containing a sampler just
        * ignores the sampler present in the type.
        */
-      return new(mem_ctx) ir_constant(true);
+      break;
+
+   default:
+      assert(!"Should not get here.");
+      break;
    }
 
-   return NULL;
+   if (cmp == NULL)
+      cmp = new(mem_ctx) ir_constant(true);
+
+   return cmp;
 }
 
 ir_rvalue *
@@ -888,7 +891,7 @@ ast_expression::hir(exec_list *instructions,
       result = do_comparison(ctx, operations[this->oper], op[0], op[1]);
       type = glsl_type::bool_type;
 
-      assert(result->type == glsl_type::bool_type);
+      assert(error_emitted || (result->type == glsl_type::bool_type));
       break;
 
    case ast_bit_and:




More information about the mesa-commit mailing list