In the following example the typecast (sign extension) from int
(32bit) to long (64bit) is missing. Before the compare the signed i1
is < 0 and unsigned u2 is > 0 and this should be kept when casting to
64bit long. Same issue for long long (also 64bit).
So we get correct ov=1 with gcc version <= 4.2, but wrong ov=0 with
gcc version >= 4.3. 
This issue occurs with and without optimization.

gcc version:  gcc-4_3_branch and trunk svn revision 133752
              (gcc-4_2 and below runs fine)


int main()
{
  int ov;
  unsigned u2;
  int i1;

  i1 = 0;
  u2 = (unsigned)2147483647 + 1 ;
  (i1) += (u2);
  if ( (long)(i1)<(long)(u2) ) ov = 1; else ov = 0;

  return !ov;
}


-- 
           Summary: typecast (sign extension) missing
           Product: gcc
           Version: 4.3.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: holger dot hopp at sap dot com
 GCC build triplet: x86_64-unknown-linux-gnu
  GCC host triplet: x86_64-unknown-linux-gnu
GCC target triplet: x86_64-unknown-linux-gnu


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=35900

Reply via email to