Comment

Comment by mikewarot

Free Pascal (fpc) supports trapping on overflow, it uses the overflow flag and tests it after integer operations, it's pretty basic. Here's the assembly output of in Int64 add

  # [16] c := a + b;
    movq U_$P$TEST_$$_A(%rip),%rdx
    movq U_$P$TEST_$$_B(%rip),%rax
    addq %rdx,%rax
    jno .Lj9
    call FPC_OVERFLOW
  .Lj9:
    movq %rax,U_$P$TEST_$$_C(%rip)
It should be easy to support in C/C++, as FPC uses the same LLVM backend.
parent mikewarot 4 years ago

Discussion

Live from the official Hacker News API

A modern reader for Hacker News · SvelteKit + Skeleton