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

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|---                         |INVALID
             Status|UNCONFIRMED                 |RESOLVED

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
With ` -fsanitize=undefined ` I get


Program returned: 0
/app/example.cpp:30:23: runtime error: signed integer overflow: -2147483648 +
-1 cannot be represented in type 'int'
/app/example.cpp:30:33: runtime error: signed integer overflow: 1 + 2147483647
cannot be represented in type 'int'

So the program has some undefined behavior in it.

Change:
  sum.lead_ = x.lead_ + y.lead_ + carry;
to:
  sum.lead_ = (unsigned)x.lead_ + (unsigned)y.lead_ + (unsigned)carry;

Fixes the errors from the sanitizer finds and fixes the testcase.

Reply via email to