This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Wrong RTL instruction deleted


Giovanni Bajo wrote:

Aliasing is about objects, not pointers. In the testcase, the code is accessing
an object of type "unsigned int" through a lvalue of type "float" and this is
undefined behaviour for the C++ standard. I guess -Wstrict-aliasing could be
improved to handle this situation if it does not already.

Interesting, so casts really have been quite surprisingly crippled in C if this is correct. I really find it quite surprising that it is impossible in standard C to write this in a straightforward way.

The corresponding Ada program:

  function Foo return Float is
     function To_Float is new Unchecked_Conversion (Unsigned_32, Float);
     MASK : unsigned := 16#8000_0000#;
  begin
     return To_Float (MASK);
  end Foo;

is certainly 100% valid since the value converted is a valid
value of the target type. It is only when you start producing
counterfit pointers in Ada that you start getting into undefined
territory.

Presumably the Ada program would fail in the same way. I have
felt for a while that we should probably set -fno-strict-aliasing
by default in GNAT, and if this is really true, it adds fuel to
the argument for doing this.

P.S. of course in Ada you would just write return -0.0 and know
that it would work, but that's another story :-)




Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]