A loop is generated for the wrapper of the switch statement. We need to force
the exit of that loop after all cases are processed. Therefore, generate
an implicit break at the very end of the loop.
---
 src/glsl/ast_to_hir.cpp |    8 ++++++++
 1 files changed, 8 insertions(+), 0 deletions(-)

diff --git a/src/glsl/ast_to_hir.cpp b/src/glsl/ast_to_hir.cpp
index c409c2d..b4ba5a2 100644
--- a/src/glsl/ast_to_hir.cpp
+++ b/src/glsl/ast_to_hir.cpp
@@ -3364,9 +3364,17 @@ ir_rvalue *
 ast_switch_body::hir(exec_list *instructions,
                     struct _mesa_glsl_parse_state *state)
 {
+   void *ctx = state;
+   
    if (stmts != NULL)
       stmts->hir(instructions, state);
       
+   // append break to force loop exit
+   ir_jump *const break_stmt =
+      new(ctx) ir_loop_jump(ir_loop_jump::jump_break);
+
+   instructions->push_tail(break_stmt);
+
    /* Switch bodies do not have r-values.
     */
    return NULL;
-- 
1.7.4.1

_______________________________________________
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/mesa-dev

Reply via email to