]> git.tdb.fi Git - libs/gl.git/blobdiff - source/glsl/optimize.cpp
Fix a name conflict in certain inlining scenarios
[libs/gl.git] / source / glsl / optimize.cpp
index c9d3c33a543830f3618a6d2e337d92519026de6c..64ceddcc16ba92968c2f0d517f0230bb8e739598 100644 (file)
@@ -114,9 +114,13 @@ string InlineContentInjector::apply(Stage &stage, FunctionDeclaration &target_fu
        source_func = call.declaration->definition;
 
        /* Populate referenced_names from the target function so we can rename
-       variables from the inlined function that would conflict. */
+       variables from the inlined function that would conflict.  Only consider
+       names which declared in blocks linearly related to the target block. */
        pass = REFERENCED;
-       target_func.visit(*this);
+       tgt_blk.visit(*this);
+       for(const Block *b=&tgt_blk; b; b=b->parent)
+               for(const auto &kvp: b->variables)
+                       referenced_names.insert(kvp.first);
 
        /* Inline and rename passes must be interleaved so used variable names are
        known when inlining the return statement. */
@@ -402,7 +406,7 @@ void ExpressionInliner::visit(Swizzle &swizzle)
 
 void ExpressionInliner::visit(UnaryExpression &unary)
 {
-       SetFlag set_write(access_write, access_write || unary.oper->token[1]=='+' || unary.oper->token[1]=='-');
+       SetFlag set_write(access_write, (unary.oper->token[1]=='+' || unary.oper->token[1]=='-'));
        visit(unary.expression);
        r_trivial = false;
 }