Do you mean it as a philosophical POV or that gcc will optimize "if (p)" away based on this assumption?
-
-
Replying to @ch3root
I meant it philosophically, but now I have investigated and ugh https://godbolt.org/g/piu9ka cc
@RichFelker1 reply 0 retweets 0 likes -
I am pretty sure it's possible to merge these to programs into one that shows GCC is as wrong as Clang on this.
1 reply 0 retweets 0 likes -
oops that was still Clang being wrong in that link, no sign of GCC being inconsistent so far.
1 reply 0 retweets 0 likes -
Replying to @volatile_void @ch3root
Indeed. The invalid optimization clang is making is assuming malloc doesn't fail. Unless GCC also does that, GCC is ok.
1 reply 0 retweets 1 like -
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 @ch3root
You're saying: change which leads to resource exhaustion? Agree: broken. What if observing change needs UB?
2 replies 0 retweets 0 likes
There's no such thing as needing UB to observe behavior. A program with UB doesn't have behavior.
-
-
Replying to @RichFelker @ch3root
would you object to optimizations which could only be observed through UB? In some cases IMHO bad idea.
0 replies 0 retweets 0 likesThanks. Twitter will use this to make your timeline better. UndoUndo
-
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.