mirror of
https://github.com/sfall-team/sslc.git
synced 2026-07-27 16:52:49 -07:00
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:
+9
-1
@@ -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]) {
|
||||
|
||||
Reference in New Issue
Block a user