Full optimization: don't eliminate proc args if any consequent args were used, to prevent invalid values (closes #4)

- This happens because proc will still have it's original arg count and calling side will still pass all arguments, but inside the proc, wrong argument will be used, due to how variable removal works
This commit is contained in:
phobos2077
2023-05-25 01:48:32 +02:00
parent 9c602f039c
commit 8162a01b63
+9 -1
View File
@@ -715,7 +715,15 @@ static void DeadVariableRemoval(NodeList* _nodes, VariableList* vars, int numArg
int *uses = (int*)calloc(1, vars->numVariables * 4);
for (i = 0; i < vars->numVariables; i++) uses[i] = 0;
for (i = 0; i < _nodes->numNodes; i++) {
if (nodes[i].token == T_SYMBOL && (var = LookupVariable(&nodes[i])) != -1) uses[var]++;
if (nodes[i].token == T_SYMBOL && (var = LookupVariable(&nodes[i])) != -1) {
uses[var]++;
// If any proc argument is used, mark all previous as used too, to prevent argument values being swapped.
if (var < numArgs) {
for (j = 0; j < var; j++) {
if (uses[j] == 0) uses[j]++;
}
}
}
}
for (i = vars->numVariables - 1; i >= 0;i--) {
if (!uses[i]) {