Re:Defining the Undefinedness of C (2015) [pdf]
by smitherfield on Wednesday July 26, 2017 @02:29PM
(#14858816)
Rust does do the loop condition (well, comparing `my_signed_int` to INT_MAX) even with optimizations: https://godbolt.org/g/dnBEJi
(You need to put a side effect such as I/O in the conditional branch for it not be optimized away, "pub" before the function declaration for it not to be eliminated as dead code, and pass `my_signed_int` as an argument so the condition isn't constant-folded).
Clang OTOH optimizes away the condition with even the lowest optimization level (-Og) turned on, as you'd expect: https://godbolt.org/g/8ftkED
Re:Defining the Undefinedness of C (2015) [pdf]
by steveklabnik on Thursday July 27, 2017 @11:35AM
(#14866240)
Ah, nicely done.
I tried to toss this into godbolt, but the optimizer is too good of course, it will optimize away the entire if if my_signed_int is a literal. Here's one without optimizations: https://godbolt.org/g/tBZcTA
It seems to compare 1 to 1, and then branch. My guess, though this isn't my area of specialty, is that this is because it is also assuming that overflow can't happen, making this always true.
Clang, interestingly enough, does the load, add, and compare https://godbolt.org/g/gPjgVc