https://gcc.gnu.org/bugzilla/show_bug.cgi?id=59708

--- Comment #9 from Martin von Gagern <Martin.vGagern at gmx dot net> ---
(In reply to Andrew Pinski from comment #8)
> I rather not have builtins as you can write portable C code that detects
> overflow just fine.  GCC could have internal functions if needed which are
> used when converting the pattern for detecting overflow.

Then it sounds as if bug #48580 should cater for your needs. Although bug
#48580 comment #7 raised the concern that there appears to be no commonly
established pattern, therefore detecting such patterns would become difficult.

http://stackoverflow.com/q/199333/1468366 also discusses overflow detection
patterns, and the current highest-voted answer is a performance nightmare. But
better solutions seem impossible due to the fact that according to (at least
some version of) the language specs, signed overflow leads to undefined
behavior, so the overflow has to be detected before the operation is performed.

If you want to prove me wrong, answer bug #48580 comment #5 with your favorite
pattern and show examples to support that this is in reasonably wide-spread
use.

I believe that builtins would be easier to read and easier to maintain. To me,
this sounds like an overall win, albeit at the cost of portability. But with
this proposal here we'd at least have compatibility with clang.

In any case, I don't think there is a reason against supporting both, a builtin
and a pattern detection. I consider the former far more realistic in the
forseeable future, and the latter can build on that internally.

Reply via email to