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
If you run the following piece of code in release mode, instead of going into an infinite loop (like in debug mode) the program terminates.
fnfermat() -> bool{constMAX:i32 = 1000;let(mut a,mut b,mut c) = (1,1,1);loop{if(a * a * a) == ((b * b * b) + (c * c * c)){returntrue;};
a += 1;if a > MAX{
a = 1;
b += 1;}if b > MAX{
b = 1;
c += 1;}if c > MAX{
c = 1;}}}fnmain(){iffermat(){println!("Fermat's Last Theorem has been disproved.");}else{println!("Fermat's Last Theorem has not been disproved.");}}
This is a "known" LLVM "bug". There is lots of discussion to what the right course of action is. One might say this is a convoluted example. But observe! The following program should not terminate after a rather trivial value range analysis:
fnf() -> bool{letmut a = 1;loop{if a == 2000{returntrue;}
a += 1;if a > 1000{
a = 1;}}}fnmain(){assert!(f());}
Still, the above program terminates in release mode, which is obviously riddiculous. It get's even crazier when you omit the return value:
fnf(){letmut a = 1;while a != 2000{if a > 1000{
a = 1;}}}fnmain(){f();}
If you run the following piece of code in release mode, instead of going into an infinite loop (like in debug mode) the program terminates.
Obviously this has been ripped off http://blog.regehr.org/archives/140 100% (it's an exact transcript from the C code shown there)
This is a "known" LLVM "bug". There is lots of discussion to what the right course of action is. One might say this is a convoluted example. But observe! The following program should not terminate after a rather trivial value range analysis:
Still, the above program terminates in release mode, which is obviously riddiculous. It get's even crazier when you omit the return value:
This function optimizes to the following LLVM-IR:
Now we can go have a party. The following code prints out the numbers from 0 to 99...
TLDR: LLVM removes side-effect free infinite loops that contain an unreachable loop abort.
The text was updated successfully, but these errors were encountered: