CppCon 2016: Chandler Carruth “Garbage In, Garbage Out: Arguing about Undefined Behavior..."
Video Statistics and Information
Channel: CppCon
Views: 63,158
Rating: 4.7447915 out of 5
Keywords: Chandler Carruth, CppCon 2016, Computer Science (Field), + C (Programming Language), Bash Films, conference video recording services, conference recording services, nationwide conference recording services, conference videography services, conference video recording, conference filming services, conference services, conference recording, conference live streaming, event videographers, capture presentation slides, record presentation slides, event video recording
Id: yG1OZ69H_-o
Channel Id: undefined
Length: 57min 39sec (3459 seconds)
Published: Thu Oct 06 2016
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.
At around 48 minutes someone asks why they can't produce the fast code for the function with unsigned 32 bit integers and Chandler explains that that would be incorrect because the code would do different things if the indices actually were close enough to INT_MAX to cause wrapping.
However there's a way around that: the compiler could generate the fast code and then also generate code to check the arguments. Then have a second, slow code path that gets used with the check sees that wrapping would occur. In practice you'd always get the fast code path and all you'd have to pay is for the extra checking up front to ensure the fast path is okay, and the extra code size hopefully in some far away and very cold place in the executable.
Here's the part I don't understand about UB that I didn't even know I didn't understand until Chandler mentioned it @ ~6:33 (still at the beginning of the video so maybe this is addressed later).
Standard C++ defines dereferencing a nullptr as UB. He mentions the reason for this is that on some platforms dereferencing 0x0 is not possible to detect at runtime on some platforms and on some platforms it's defined behaviour. He then makes the case that we don't want to exclude C++ from those platforms (which makes sense).
However, aren't we now in a contradictory state? Dereferencing nullptr is UB that the optimizer exploits to generate unexpected code (e.g. a typical optimization the compiler does is prune codepaths that dereference nullptr), which is now invalid code on the platform we wanted to support where dereferencing nullptr is well-defined. How is this contradiction resolved? Does the optimizer conspire with the platform-specific codegen layer to figure out if a given behaviour is UB on a given platform or not?
So, is there a proposal for unsigned types with undefined overflow?
Kind of disappointed by him about dragging up old out of context tweets to try to make some point. "If you're arguing, you're losing", well guess what...