glsl: give all unnamed structs the same name
[mesa.git] / src / compiler / glsl / lower_jumps.cpp
index ed1b6d1ea633c65a3b10f11086f1903b943cb7e9..7dc34056a1b1dc14d00684cb8a8952fe90fba616 100644 (file)
@@ -932,14 +932,27 @@ lower_continue:
              * break statement if necessary.
              */
             return_if->then_instructions.push_tail(new(ir) ir_loop_jump(ir_loop_jump::jump_break));
-         else
-            /* Otherwise, all we need to do is ensure that the
-             * instructions that follow are only executed if the
-             * return flag is clear.  We can do that by moving those
-             * instructions into the else clause of the generated if
+         else {
+            /* Otherwise, ensure that the instructions that follow are only
+             * executed if the return flag is clear.  We can do that by moving
+             * those instructions into the else clause of the generated if
              * statement.
              */
             move_outer_block_inside(ir, &return_if->else_instructions);
+
+            /* In case the loop is embedded inside an if add a new return to
+             * the return flag then branch and let a future pass tidy it up.
+             */
+            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);
       }