From: Mikko Rasa Date: Wed, 3 Mar 2021 16:48:34 +0000 (+0200) Subject: Fix an issue where member assignments were incorrectly optimized away X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=455fbb0b9c7d7c4b66cc969ad0e9915fe95e420f;p=libs%2Fgl.git Fix an issue where member assignments were incorrectly optimized away They are now treated as subfield assignments, same as array subscripts. --- diff --git a/source/glsl/optimize.cpp b/source/glsl/optimize.cpp index 8a9992a2..afa6394e 100644 --- a/source/glsl/optimize.cpp +++ b/source/glsl/optimize.cpp @@ -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 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 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); } diff --git a/source/glsl/optimize.h b/source/glsl/optimize.h index 373e0199..28f5e876 100644 --- a/source/glsl/optimize.h +++ b/source/glsl/optimize.h @@ -145,7 +145,7 @@ private: std::vector variables; Assignment *r_assignment; bool assignment_target; - bool r_assign_to_subscript; + bool r_assign_to_subfield; bool r_side_effects; public: