Simplification of relational expressions

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



I have a question about some relational expressions being transformed
into constants when neither wrapping nor strict signed overflow is used.
Here is the example I was looking at:

  extern int get_int (void);
  extern void foo (int);

  int
  main (void)
  {
    int a = get_int ();
    foo (a + 1 >  a);
    foo (a + 1 >= a);
    foo (a + 1 == a);
    foo (a + 1 <= a);
    foo (a + 1 <  a);
    foo (a + 1 != a);
    return 0;
  }
  
I was under the impression that none of these would be simplified into
constants when using `-fno-wrapv -fno-strict-overflow'.  But this is
what is dumped into 003t.original with the current trunk.

  {
    int a = get_int ();
    foo (a + 1 > a);
    foo (a + 1 >= a);
    foo (0);
    foo (a + 1 <= a);
    foo (a + 1 < a);
    foo (1);
    return 0;
  }

Is there a reason that the equality and inequality expressions (and only
those expressions) are simplified?  I understand that signed integer
overflow is undefined.

By the way, if I instead use Ubuntu's GCC 4.2.3 I get what I expect (no
simplification):

  {
    int a = get_int ();
    foo (a + 1 > a);
    foo (a + 1 >= a);
    foo (a + 1 == a);
    foo (a + 1 <= a);
    foo (a + 1 < a);
    foo (a + 1 != a);
    return 0;
  }


Chris

[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux