Comment by jcranmer

2 years ago

The LLVM calling conventions for x86 only allow returning 3 integer registers, 4 vector registers, and 2 x87 floating point registers (er, stack slots technically because x87 is weird).

Sure. That would be an instance of the "usual error". The argument registers are usually caller save, where any unused ones get treated as scratch in the callee, in which case making them all available for returning data as well is zero cost.

There's no reason not to, other than C makes returning multiple things awkward and splitting a struct across multiple registers is slightly annoying for the compiler.

Limiting a newly designed Rust ABI to whatever LLVM happens to support at the moment seems unnecessarily limiting. Yeah, you'd need to write some C++ to implement it, but that's not the end of the world, especially compared to getting stuck with arbitrary limits in your ABI for the next decade or two.

  • This sort of thing is why integer division by 0 is UB in rust on targets where it's not UB, because it's UB in LLVM :)

    • I stared at this really hard, and I eventually couldn't figure out what you mean here.

      Obviously naively just dividing integers by zero in Rust will panic, because that's what is defined to happen.

      So you have to be thinking about a specific case where it's defined not to panic. But, what case? There isn't an unchecked_div defined on the integers. The wrapping and saturating variants panic for division by zero, as do the various edge cases like div_floor

      What case are you thinking of where "integer division by 0 is UB in Rust" ?

      5 replies →