This testcase:
------------------------------------
int bla (long l)
{
  long lR;
  if (l < 0) {
    lR = - l;
    if (lR < 0) {    // 2
      return 1;
    }
  }
  return 0;
}

extern void abort ();
int main()
{
  if (!bla (-2147483648))
    abort ();
  return 0;
}
----------------------------------

when compiled with -O2 will abort.  because the inner test 2 will
be optimized away.  The variable lR is negative at that point, but
the test won't trigger as it was removed.  This same code is used in
tcl 8.4.12 to detect if the passed number is the most negative one (like in
the above example), and special case that one.  So this code relies on
the fact that -INT_MIN is INT_MIN again, and hence both <0 test will
trigger.

Now, with -fwrapv this testcase is not miscompiled, but I'm not sure
if this behaviour of GCC is really justified by the standard and our
intention.  Certainly the -INT_MIN stored into an int is implementation
defined, and older GCCs (and in fact also the current one) stores INT_MIN
into the target.  Just deleting the test seems wrong.


-- 
           Summary: Miscompilation in tcl, -INT_MIN test misoptimized
           Product: gcc
           Version: 4.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: tree-optimization
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: matz at suse dot de
  GCC host triplet: i386-linux


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

Reply via email to