| git.druid.rocks | index | druid520 | nscc | test/ | t52_while_shortcircuit.nsc |
test/t52_while_shortcircuit.nsc
/* regression test: a while loop whose condition is a &&/|| expression
* must re-evaluate that condition on every iteration, not just once
* before the loop starts. jdesugar4's &&/|| rewrite turns "a && b"
* into real statements that compute a flag (short-circuiting b when a
* is false) plus a plain reference to that flag; the while-loop
* desugaring emitted those statements ONCE, before the loop's back-
* edge label, so every re-entry via the bottom-of-loop goto re-tested
* the same stale flag forever instead of recomputing it. found via
* kaboom's kfs directory listing looping forever on a real disk once
* a directory had a non-empty first entry (the exact "j < n &&
* arr[j] != 0" shape below). */
global i32
main(void)
{
i32 j;
i32 arr[8];
arr[0] = 1;
arr[1] = 1;
arr[2] = 1;
arr[3] = 0;
arr[4] = 1;
arr[5] = 1;
arr[6] = 1;
arr[7] = 1;
j = 0;
while(j < 8 && arr[j] != 0)
{
j = j + 1;
}
return j;
}