Skip to content

Collection of cases of deliberate UB #158

Closed
@RalfJung

Description

Sometimes crates deliberately cause UB because there is no other way to do what they need, or because the alternatives are unacceptably worse in some sense. This is not great, but it is valuable feedback for us -- we should try to either make those things not UB, or provide UB-free alternatives that are good enough!

Some cases:

  • crossbeam's AtomicCell does various things with uninitialized memory. Most of this would be fine if we allowed uninitialized integers and adapted LLVM's handling of data races, but compare_exchange is worse.
  • bytes does a non-atomic plain load that races, because relaxed loads cost too much performance. (Note that LLVM's handling of data races is not enough here, data races still return garbage data. Also see this thread on using "unordered".)
  • Every offset_of macro everywhere, in particular
  • Unwinding through FFI boundaries is used in mozjpeg-sys and possibly other image-related libs. One of many long discussions on the issue is here.

In this issue, please let's only discuss whether something is UB according to current rules. if you want to talk about ways to improve the code or the spec to avoid UB, open a new issue (or there might already be one).

Metadata

Assignees

No one assigned

    Labels

    C-listCategory: A list/collection of some sort. Please help maintain it!

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions