Rust-GCC / gccrs

GCC Front-End for Rust
https://rust-gcc.github.io/
GNU General Public License v2.0
2.37k stars 152 forks source link

Overflow traps #924

Open philberty opened 2 years ago

philberty commented 2 years ago

GCC has plenty of builtin_overflow functions ADA has overflow traps akin to rust so we should be able to port this function:

https://github.com/Rust-GCC/gccrs/blob/c7275a7fb89f324e7cd7881d12a49287a89f1c74/gcc/ada/gcc-interface/trans.cc#L9531-L9726

bjorn3 commented 2 years ago

Does that emit a trap instruction? In rustc with overflow checks enabled the panic handler is called instead. Providing a trap instruction as option in addition to wrapping and calling the panic handler on overflow may be fine though.

philberty commented 2 years ago

I use the word trap, as in to trap the case of when overflow occurs we can amend this to call whatever panic handler we want. I am linking to this code fragment just so we can find the code to call into the internal builtin functions which GCC to get the overflow condition.