News for hackers. Stuff that matters.
Re:Clang emits memcpy for std::swap, which can introduce und... by colin_mccabe on Monday April 25, 2016 @12:32AM (#11562525)
LLVM is a very impressive compiler. I'm really impressed with the warning messages it's able to produce (especially compared with what was available even 2 or 3 years ago).

What is more frustrating about modern compilers (and this is not limited to LLVM) is the desire to squeeze out a tiny bit more performance by exploiting undefined behavior. I'm thinking of things like eliminating calls to memset that "don't seem to do anything user-visible," eliminating code based on signed overflow being undefined, and so on.

Most of the the undefined behavior that exists in C is there because different machines used to do different things. For example, there used to be non-two's-complement machines. It wasn't put there because C was somehow designed to be hyper-optimized. People who relied on the undefined behavior could legitimately make the same argument that you are now making-- that it worked fine on their machine, which they knew very well.

I am curious why nobody has brought up the idea of making memmove as efficiently handled as memset, rather than using undefined behavior here. UB feels like the wrong way to go.

Re:Clang emits memcpy for std::swap, which can introduce und... by ploxiln on Monday April 25, 2016 @02:25AM (#11562758)
You may be thinking of "implementation-defined behavior" which is not exactly the same as "undefined behavior".