glsl: fix lower jumps for nested non-void returns
authorTimothy Arceri <tarceri@itsqueeze.com>
Fri, 7 Apr 2017 01:24:37 +0000 (11:24 +1000)
committerTimothy Arceri <tarceri@itsqueeze.com>
Sat, 8 Apr 2017 01:18:32 +0000 (11:18 +1000)
Fixes the case were a loop contains a return and the loop is
nested inside an if.

Reviewed-by: Roland Scheidegger <sroland@vmware.com>
https://bugs.freedesktop.org/show_bug.cgi?id=100303

src/compiler/glsl/lower_jumps.cpp
src/compiler/glsl/tests/lower_jumps/create_test_cases.py

index e165172301ab91536d77d009eaed36a31a01ad66..7dc34056a1b1dc14d00684cb8a8952fe90fba616 100644 (file)
@@ -945,6 +945,12 @@ lower_continue:
              */
             if (this->function.signature->return_type->is_void())
                return_if->then_instructions.push_tail(new(ir) ir_return(NULL));
+            else {
+               assert(this->function.return_value);
+               ir_variable* return_value = this->function.return_value;
+               return_if->then_instructions.push_tail(
+                  new(ir) ir_return(new(ir) ir_dereference_variable(return_value)));
+            }
          }
 
          ir->insert_after(return_if);
index 20f5ace199eeef34b0fb117cc684b0c5308a7a9d..623487eb44c4a34b75beceee5f2d3a4bbd75659c 100644 (file)
@@ -628,7 +628,10 @@ def test_lower_return_non_void_at_end_of_loop():
             loop(assign_x('a', const_float(1)) +
                  lowered_return_simple(const_float(2)) +
                  break_()) +
-            if_not_return_flag(assign_x('b', const_float(3)) +
+            if_return_flag(assign_x('return_value', '(var_ref return_value)') +
+                           assign_x('return_flag', const_bool(1)) +
+                           assign_x('execute_flag', const_bool(0)),
+                           assign_x('b', const_float(3)) +
                                lowered_return(const_float(4))) +
             final_return()
             ))