News for hackers. Stuff that matters.
Re:Undefined behavior can result in time travel by scott_s on Saturday June 28, 2014 @09:42AM (#7958173)
Great example, however this does not apply to free - or I would be very surprised if it did. It is relatively common for people to override malloc and free at runtime, so I would be very surprised if the compiler treated malloc or free as a compiler intrinsic, and inlined the code. I would not be surprised, however, if the compiler used the semantics of malloc or free to reason about the surrounding code. The original point, however, was about inlined code leading to generated code that no reasonable person would write (null check after use). So I still think that would not happen for free.
Re:Undefined behavior can result in time travel by mikeash on Saturday June 28, 2014 @11:26AM (#7958410)
I just tested clang, and free(malloc(42)); gets completely optimized out, as does free(NULL);. free(argv) doesn't, so it's not quite that clever, at least.