From 52893327fb0cc085df6b7b38de0cf240d5f9ae5e Mon Sep 17 00:00:00 2001 From: Timothy Arceri Date: Mon, 23 Aug 2021 18:54:16 +1000 Subject: [PATCH] glsl: fix variable scope for do-while loops Without this the following code was successfully compiling. void main() { do int var_1 = 0; while (false); var_1++; } Fixes: a87ac255cf7e ("Initial commit. lol") Reviewed-by: Ian Romanick Part-of: --- src/compiler/glsl/ast_to_hir.cpp | 9 ++++++++- src/compiler/glsl/glsl_parser.yy | 2 +- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/compiler/glsl/ast_to_hir.cpp b/src/compiler/glsl/ast_to_hir.cpp index 07a39a2d9ce..3a5c0a1b6a8 100644 --- a/src/compiler/glsl/ast_to_hir.cpp +++ b/src/compiler/glsl/ast_to_hir.cpp @@ -7141,9 +7141,16 @@ ast_iteration_statement::hir(exec_list *instructions, if (rest_expression != NULL) rest_expression->hir(&rest_instructions, state); - if (body != NULL) + if (body != NULL) { + if (mode == ast_do_while) + state->symbols->push_scope(); + body->hir(& stmt->body_instructions, state); + if (mode == ast_do_while) + state->symbols->pop_scope(); + } + if (rest_expression != NULL) stmt->body_instructions.append_list(&rest_instructions); diff --git a/src/compiler/glsl/glsl_parser.yy b/src/compiler/glsl/glsl_parser.yy index ec66e680a2b..4111c45c97d 100644 --- a/src/compiler/glsl/glsl_parser.yy +++ b/src/compiler/glsl/glsl_parser.yy @@ -2743,7 +2743,7 @@ iteration_statement: NULL, $3, NULL, $5); $$->set_location_range(@1, @4); } - | DO statement WHILE '(' expression ')' ';' + | DO statement_no_new_scope WHILE '(' expression ')' ';' { void *ctx = state->linalloc; $$ = new(ctx) ast_iteration_statement(ast_iteration_statement::ast_do_while,