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

--- Comment #3 from Steve Ellcey <sje at gcc dot gnu.org> ---
My understanding (I don't have a C/C++ standard handy) is that the addition
done by 'ret + a[i]' is done in integer mode (not as short).  This results in
an integer value that may be outside the range of a short, but in the
range of a normal integer.  So this is not really an overflow.   Then the
integer result is assigned to ret, which is short.  I believe that the
truncation of a integer value (with a value outside the range of a short)
to a short is not undefined by the C and C++ standards but has a specific
way that it needs to work (truncate off the higher bits).  This is the
truncation that needs to be done on each loop iteration.

Reply via email to