Skip to content

Do not hoist declarations of mutated variables

Declarations/initializations of non-constant variables must not be hoisted from loops because it changes the semantics of the code.

For example:

for (...) {
  int i = 0; // <- rhs is invariant but lhs is not
  for (...) {
    i += 1;
  }
}

Previously got falsly transformed to:

int i = 0;
for (...) {
  for (...) {
    i += 1;
  }
}

Merge request reports