Mesa (master): glsl: Semantically check the RHS of `||' even when short-circuiting.

Eric Anholt anholt at kemper.freedesktop.org
Wed Apr 13 18:08:53 PDT 2011


Module: Mesa
Branch: master
Commit: 9e04b190b5f59c5b375645f5756a6edd98a7f90c
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=9e04b190b5f59c5b375645f5756a6edd98a7f90c

Author: Eric Anholt <eric at anholt.net>
Date:   Sat Apr  9 10:27:02 2011 -1000

glsl: Semantically check the RHS of `||' even when short-circuiting.

We just do the AST-to-HIR processing, and only push the instructions
if needed in the constant false case.

Fixes glslparsertest/glsl2/logic-02.frag

Reviewed-by: Kenneth Graunke <kenneth at whitecape.org>
Reviewed-by: Chad Versace <chad.versace at intel.com>
Reviewed-by: Ian Romanick <ian.d.romanick at intel.com>

---

 src/glsl/ast_to_hir.cpp |   11 +++++------
 1 files changed, 5 insertions(+), 6 deletions(-)

diff --git a/src/glsl/ast_to_hir.cpp b/src/glsl/ast_to_hir.cpp
index d92a437..108c7c3 100644
--- a/src/glsl/ast_to_hir.cpp
+++ b/src/glsl/ast_to_hir.cpp
@@ -1151,16 +1151,18 @@ ast_expression::hir(exec_list *instructions,
    }
 
    case ast_logic_or: {
+      exec_list rhs_instructions;
       op[0] = get_scalar_boolean_operand(instructions, state, this, 0,
 					 "LHS", &error_emitted);
+      op[1] = get_scalar_boolean_operand(&rhs_instructions, state, this, 1,
+					 "RHS", &error_emitted);
 
       ir_constant *op0_const = op[0]->constant_expression_value();
       if (op0_const) {
 	 if (op0_const->value.b[0]) {
 	    result = op0_const;
 	 } else {
-	    result = get_scalar_boolean_operand(instructions, state, this, 1,
-						"RHS", &error_emitted);
+	    result = op[1];
 	 }
 	 type = glsl_type::bool_type;
       } else {
@@ -1172,15 +1174,12 @@ ast_expression::hir(exec_list *instructions,
 	 ir_if *const stmt = new(ctx) ir_if(op[0]);
 	 instructions->push_tail(stmt);
 
-	 op[1] = get_scalar_boolean_operand(&stmt->else_instructions,
-					    state, this, 1,
-					    "RHS", &error_emitted);
-
 	 ir_dereference *const then_deref = new(ctx) ir_dereference_variable(tmp);
 	 ir_assignment *const then_assign =
 	    new(ctx) ir_assignment(then_deref, new(ctx) ir_constant(true), NULL);
 	 stmt->then_instructions.push_tail(then_assign);
 
+	 stmt->else_instructions.append_list(&rhs_instructions);
 	 ir_dereference *const else_deref = new(ctx) ir_dereference_variable(tmp);
 	 ir_assignment *const else_assign =
 	    new(ctx) ir_assignment(else_deref, op[1], NULL);



More information about the mesa-commit mailing list