On 22 Mar 2015, at 22:01, Craig Rodrigues <rodrigc_at_FreeBSD.org> wrote: > >> Volatile is not the solution, it is completely orthogonal. The correct >> way would be to use unsigned integers, for which wrapping is defined, >> then convert those back and forth when presenting the results to the >> user. >> > > OK, converting expr.y to use unsigned integers would require a bit of work. Note that clang has, for a few releases, had builtins that allow overflow-checked operations and will generate very efficient code. In op_times, I believe the following should work: long long mul; #if __has_builtin(__builtin_smulll_overflow) if (__builtin_smulll_overflow(a->u.i, b->u.i, &mul)) errx(ERR_EXIT, "overflow"); #else mul = a->u.i * b->u.i; #endif r = make_integer(mul); I don't know if recent versions of gcc implement these builtins yet. I think they were added to clang around 3.4, possibly slightly earlier. DavidReceived on Mon Mar 23 2015 - 08:39:30 UTC
This archive was generated by hypermail 2.4.0 : Wed May 19 2021 - 11:40:56 UTC