News for hackers. Stuff that matters.
Re:Clang emits memcpy for std::swap, which can introduce und... by Dylan16807 on Sunday April 24, 2016 @05:17PM (#11561410)
The compiler has different layers. Layer X is nonconforming, which causes undefined behavior in layer M.

Layer M's memcpy doesn't have to have the same semantics as the C standard's memcpy, but the bug report implies that it does.

Re:Clang emits memcpy for std::swap, which can introduce und... by kazinator on Sunday April 24, 2016 @05:19PM (#11561415)
Yes, if "undefined behavior" doesn't just mean "a situation where the ISO language standard doesn't impose a requirement", but has a broader meaning like "behavior not defined by anyone at all".
Re:Clang emits memcpy for std::swap, which can introduce und... by Dylan16807 on Sunday April 24, 2016 @05:30PM (#11561447)
The compiler is using the ISO language standard to define the behavior of an internal piece. It is then using that piece in the wrong way. It's not generic "not defined" behavior, it is specific C "undefined behavior".

Think of that part of the transformed code as still C for relevant purposes.

Re:Clang emits memcpy for std::swap, which can introduce und... by chandlerc1024 on Sunday April 24, 2016 @06:39PM (#11561698)
I want to assure you that the compiler does not exclusively use the ISO language standard to define the behavior of internal components of the implementation.
Re:Clang emits memcpy for std::swap, which can introduce und... by Dylan16807 on Sunday April 24, 2016 @07:45PM (#11561859)
I'm talking about a specific component named memcpy. Obviously this does not apply to other components.

And even that is only if the bug report is correct.

Re:Clang emits memcpy for std::swap, which can introduce und... by chandlerc1024 on Sunday April 24, 2016 @08:18PM (#11561935)
The compiler is not producing C code that calls memcpy. It is leveraging a specific implementation of a memcpy symbol in a particular system library. The contract between Clang and that system library can include guarantees not provided by any ISO standard.
Re:Clang emits memcpy for std::swap, which can introduce und... by Dylan16807 on Sunday April 24, 2016 @08:40PM (#11561979)
Then the bug report is wrong, and disregard the second and third posts I made. They depend on the bug report not being wrong.

My first post is generic and not about this particular issue; it's still fine.

Re:Clang emits memcpy for std::swap, which can introduce und... by whitequark_ on Sunday April 24, 2016 @09:06PM (#11562059)
The bug report is not wrong. Rather, whether the current behavior is correct depends on the platform.

For example, Darwin's libc offers this contract for memcpy and clang is perfectly within its rights to generate such code (note that the IR it generates is still violating LLVM's contract on the memcpy intrinsic); glibc offers no such contract for memcpy, and so clang's code is nonconformant.