[rust-dev] Integer overflow, round -2147483648

John Regehr regehr at cs.utah.edu
Mon Jun 23 13:01:46 PDT 2014

> I doubt it, since Swift has a high level IR above LLVM IR and the
> implementation isn't open-source. The language-specific optimizations
> like removing overflow / bounds checks based on type system rules will
> almost certainly be done on the high-level SIL IR, not at the LLVM IR
> layer where most of the information is already lost.

No, the overflow checks in Swift will turn into LLVM intrinsics such as 
llvm.sadd.with.overflow.  This is also what Rust would use.  Then, the 
IR-level optimizations will try to remove these.  LLVM already has a 
not-great integer range analysis that could be beefed up significantly 
without a whole lot of trouble.

Of course there's nothing stopping higher-level analyses from also 
attempting to avoid unnecessary overflow checks but I doubt that much or 
any of this is being done.

> Rust 1.0 will be released in about 6 months, and these improvements
> aren't going to happen in that time. It's a language for the present,
> not one written for a fantasy architecture / compiler backend in 2025.

I wasn't arguing that Rust 1.0 should trap on integer overflow, I was 
arguing that the overhead of overflow checking isn't as high as you say. 
  But I'd be happy to look at real data.


More information about the Rust-dev mailing list