From: Mikko Rasa Date: Wed, 3 Mar 2021 23:56:26 +0000 (+0200) Subject: Fix function inlining in iteration init statement X-Git-Url: http://git.tdb.fi/?p=libs%2Fgl.git;a=commitdiff_plain;h=0c07531f8ec779edde9ebe765b3cd79a6960b838 Fix function inlining in iteration init statement Also reword the other related comment to be more accurate. --- diff --git a/source/glsl/optimize.cpp b/source/glsl/optimize.cpp index a999a654..0af24e3e 100644 --- a/source/glsl/optimize.cpp +++ b/source/glsl/optimize.cpp @@ -289,11 +289,15 @@ void FunctionInliner::visit(Conditional &cond) void FunctionInliner::visit(Iteration &iter) { - SetForScope set_block(current_block, &iter.body); + /* Visit the initialization statement before entering the loop body so the + inlined statements get inserted outside. */ if(iter.init_statement) iter.init_statement->visit(*this); - /* Skip the condition and loop expression parts because they're executed on - every iteration of the loop */ + + SetForScope set_block(current_block, &iter.body); + /* Skip the condition and loop expression parts because they're not properly + inside the body block. Inlining anything into them will require a more + comprehensive transformation. */ iter.body.visit(*this); }