On 22 Mar 2015, at 22:01, Craig Rodrigues <rodr...@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.  

David

_______________________________________________
freebsd-current@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-current
To unsubscribe, send any mail to "freebsd-current-unsubscr...@freebsd.org"

Reply via email to