From 8bbbbb02cd5e8b56c8a96c1e5bc52d1df80f6884 Mon Sep 17 00:00:00 2001 From: Timothy Arceri Date: Mon, 23 Aug 2021 17:52:22 +1000 Subject: [PATCH] glsl: fix variable scope for loop-expression We need to evaluate the loop-expression of a for loop before we evaluate the loop body otherwise we will find the wrong variable for the following loop. int var_0 = 0; for(; var_0 < 10; var_0++) { const float var_0 = 1.0; gl_FragColor = vec4(0.0, var_0, 0.0, 0.0); } Fixes: a87ac255cf7e ("Initial commit. lol") Closes: https://gitlab.freedesktop.org/mesa/mesa/-/issues/5262 Reviewed-by: Ian Romanick Part-of: --- src/compiler/glsl/ast_to_hir.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/compiler/glsl/ast_to_hir.cpp b/src/compiler/glsl/ast_to_hir.cpp index b34e43aa428..4b9530c1fca 100644 --- a/src/compiler/glsl/ast_to_hir.cpp +++ b/src/compiler/glsl/ast_to_hir.cpp @@ -7138,11 +7138,15 @@ ast_iteration_statement::hir(exec_list *instructions, if (mode != ast_do_while) condition_to_hir(&stmt->body_instructions, state); + exec_list rest_instructions; + if (rest_expression != NULL) + rest_expression->hir(&rest_instructions, state); + if (body != NULL) body->hir(& stmt->body_instructions, state); if (rest_expression != NULL) - rest_expression->hir(& stmt->body_instructions, state); + stmt->body_instructions.append_list(&rest_instructions); if (mode == ast_do_while) condition_to_hir(&stmt->body_instructions, state);