diff options
Diffstat (limited to 'gcc')
| -rw-r--r-- | gcc/gcc/elna-generic.cc | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/gcc/gcc/elna-generic.cc b/gcc/gcc/elna-generic.cc index b786688..34ae5ee 100644 --- a/gcc/gcc/elna-generic.cc +++ b/gcc/gcc/elna-generic.cc @@ -958,10 +958,13 @@ namespace elna::gcc auto [check_label, end_label] = build_loop_head(control_variable_declaration, end_pointer, LT_EXPR, location); - for (auto *body_statement : statement->body) - { - body_statement->accept(this); - } + // The body gets its own scope, so that defer statements in it are run on + // every iteration and not once for the whole loop. + enter_scope(); + visit_statements(statement->body); + tree body_binding = leave_scope(); + append_statement(body_binding); + tree pointer_plus = do_pointer_arithmetic(boot::binary_operator::sum, control_variable_declaration, elna_word_one_node, location); append_statement(build2(MODIFY_EXPR, void_type_node, control_variable_declaration, pointer_plus)); |
