Indeed. The invalid optimization clang is making is assuming malloc doesn't fail. Unless GCC also does that, GCC is ok.
-
-
Replying to @RichFelker
Why do you think this is an invalid optimization? Compilers routinely mess with libc functions, e.g. inline memcpy.
2 replies 0 retweets 0 likes -
Replying to @ch3root
Because the behavior is changed. A call which necessarily must fail falsely succeeds.
2 replies 0 retweets 0 likes -
Replying to @RichFelker
The change of behavior is exactly the reason for optimizations.
2 replies 0 retweets 1 like -
Replying to @ch3root
All opt takes place by "as if" rule. Optimizations that violate that are not valid. Changing observable behavior is a bug
2 replies 0 retweets 0 likes -
Replying to @RichFelker
Sure. Everything boils down to the question what "observable behavior" is.
1 reply 0 retweets 0 likes -
Replying to @ch3root @RichFelker
The amount of used memory is not part of observable behavior. In the same way as the execution time is not.
3 replies 0 retweets 0 likes -
Replying to @ch3root @RichFelker
Take "int main() { char s[10000000] = {0}; }". It segfaults with -O0 but not with -O3. Is this invalid optimization?
3 replies 0 retweets 0 likes -
Replying to @ch3root
No because the original program has UB (by overflowing stack). C std actually omits this but it's obvious.
2 replies 0 retweets 0 likes -
Replying to @RichFelker @ch3root
Overflowing the stack isn't undefined though. Compilers can and should be handling it sanely like MSVC++.
3 replies 0 retweets 0 likes
The language provides no mechanism to detect/handle SO; predictable crash is QoI matter.
Loading seems to be taking a while.
Twitter may be over capacity or experiencing a momentary hiccup. Try again or visit Twitter Status for more information.