From a89c4aa0cd04cf8b3542f44b92d341c078de6ace Mon Sep 17 00:00:00 2001 From: ike709 Date: Tue, 28 Jan 2025 05:30:07 -0600 Subject: [PATCH] Fix `AssignAndPushReferenceValue` ignoring var value coercion --- DMCompiler/Optimizer/PeepholeOptimizations.cs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/DMCompiler/Optimizer/PeepholeOptimizations.cs b/DMCompiler/Optimizer/PeepholeOptimizations.cs index 6b2b9ed3e1..9341de9fa4 100644 --- a/DMCompiler/Optimizer/PeepholeOptimizations.cs +++ b/DMCompiler/Optimizer/PeepholeOptimizations.cs @@ -638,6 +638,11 @@ public bool CheckPreconditions(List input, int index) { AnnotatedBytecodeReference assignTarget = firstInstruction.GetArg(0); AnnotatedBytecodeReference pushTarget = secondInstruction.GetArg(0); + // Assigning certain values to certain vars (e.g. setting a SrcField like "dir" to null) + // actually causes the value to be coerced to something different than the value on the stack. + // We don't have a good way to identify those vars at this point, so just restrict the opt to locals and args since those shouldn't have side effects + if (pushTarget.RefType != DMReference.Type.Local && pushTarget.RefType != DMReference.Type.Argument) return false; + return assignTarget.Equals(pushTarget); }