Uninitialized memory + trivial types

No, because someone might someday build Swift for an architecture that e.g. used memory coloring to track memory regions that have been initialized, and then we might make that load trap when the coloring check failed.

Accessing uninitialized memory is UB. Accessing initialized memory after the lifetime of the allocation used to initialize it has ended (e.g. a UAF bug in C or C++) is UB. All sorts of similar mechanisms to get a wild read are UB. I would expect some mainstream HW implementations to detect some or all of these and trap accordingly sometime in the next decade.

13 Likes