You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
infinite loop optimized away unless function is exported #1658
Isn't this a long time LLVM bug present in other languages like C and C++ where an empty infinite loop results in no consequences and thus creates invalid programs? (for example there are many articles like https://stackoverflow.com/questions/59925618/how-do-i-make-an-infinite-empty-loop-that-wont-be-optimized-away). I guess the solution Zig would need for this specific case is adding in a nop op-code inside of the loop so LLVM says it "has an effect" and doesn't generate an invalid program/function.
This code, paired with zig build-obj on my master build of Zig (approx 1 week old) is producing while loops correctly in all three cases, in all four -O flags.
(pictured above: ReleaseSmall)
pubfnmain() void {while(true){}}
I've also tested this executable with all four -O flags, and this works on all of them.
Activity
IridescentRose commentedon Oct 20, 2020
Isn't this a long time LLVM bug present in other languages like C and C++ where an empty infinite loop results in no consequences and thus creates invalid programs? (for example there are many articles like https://stackoverflow.com/questions/59925618/how-do-i-make-an-infinite-empty-loop-that-wont-be-optimized-away). I guess the solution Zig would need for this specific case is adding in a
nopop-code inside of the loop so LLVM says it "has an effect" and doesn't generate an invalid program/function.IridescentRose commentedon Oct 20, 2020
This code generates as intended as we can see on GodBolt.
Sobeston commentedon Sep 22, 2021
Related: rust-lang/rust#82884 - apparently this was fixed in LLVM 12.
This code, paired with
zig build-objon my master build of Zig (approx 1 week old) is producing while loops correctly in all three cases, in all four -O flags.(pictured above: ReleaseSmall)
I've also tested this executable with all four -O flags, and this works on all of them.