Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

GCC 4.9 does have `-fsanitize=signed-integer-overflow`, and it generates pretty good code for that toy function:

    f(int, int):
        mov eax, edi
        add eax, esi
        jo  .L8
        ret
    .L8:
        ...


Older gcc versions have `-ftrapv` option, which checks overflow for signed addition, subtraction, and multiplication. However, the implementation calls libgcc functions to do the checks, resulting in non-negligible overhead.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: