]> git.tdb.fi Git - libs/gl.git/commitdiff
Fix an issue where member assignments were incorrectly optimized away
authorMikko Rasa <tdb@tdb.fi>
Wed, 3 Mar 2021 16:48:34 +0000 (18:48 +0200)
committerMikko Rasa <tdb@tdb.fi>
Thu, 4 Mar 2021 00:26:15 +0000 (02:26 +0200)
They are now treated as subfield assignments, same as array subscripts.

source/glsl/optimize.cpp
source/glsl/optimize.h

index 8a9992a2dba88a054dfeed5f5f681ba012946147..afa6394e19018a4766cb3c05252f97d18700bbbc 100644 (file)
@@ -408,7 +408,7 @@ UnusedVariableRemover::UnusedVariableRemover():
        aggregate(0),
        r_assignment(0),
        assignment_target(false),
-       r_assign_to_subscript(false),
+       r_assign_to_subfield(false),
        r_side_effects(false)
 { }
 
@@ -455,6 +455,7 @@ void UnusedVariableRemover::visit(InterfaceBlockReference &iface)
 
 void UnusedVariableRemover::visit(MemberAccess &memacc)
 {
+       r_assign_to_subfield = true;
        TraversingVisitor::visit(memacc);
        unused_nodes.erase(memacc.declaration);
 }
@@ -471,7 +472,7 @@ void UnusedVariableRemover::visit(BinaryExpression &binary)
        if(binary.oper->token[0]=='[')
        {
                if(assignment_target)
-                       r_assign_to_subscript = true;
+                       r_assign_to_subfield = true;
                binary.left->visit(*this);
                SetForScope<bool> set(assignment_target, false);
                binary.right->visit(*this);
@@ -483,7 +484,6 @@ void UnusedVariableRemover::visit(BinaryExpression &binary)
 void UnusedVariableRemover::visit(Assignment &assign)
 {
        {
-               r_assign_to_subscript = false;
                SetForScope<bool> set(assignment_target, !assign.self_referencing);
                assign.left->visit(*this);
        }
@@ -520,10 +520,11 @@ void UnusedVariableRemover::clear_assignments(VariableInfo &var_info, bool mark_
 void UnusedVariableRemover::visit(ExpressionStatement &expr)
 {
        r_assignment = 0;
+       r_assign_to_subfield = false;
        r_side_effects = false;
        TraversingVisitor::visit(expr);
        if(r_assignment && r_assignment->target_declaration)
-               record_assignment(*r_assignment->target_declaration, expr, (r_assignment->self_referencing || r_assign_to_subscript));
+               record_assignment(*r_assignment->target_declaration, expr, (r_assignment->self_referencing || r_assign_to_subfield));
        if(!r_side_effects)
                unused_nodes.insert(&expr);
 }
index 373e0199dd316cad4e3390f3e66cd1473aa7f8db..28f5e87688629634f9e05734e61cdbc1c5995ad1 100644 (file)
@@ -145,7 +145,7 @@ private:
        std::vector<BlockVariableMap> variables;
        Assignment *r_assignment;
        bool assignment_target;
-       bool r_assign_to_subscript;
+       bool r_assign_to_subfield;
        bool r_side_effects;
 
 public: