Re: GCC bug? (4.2.4 on Ubuntu 8.04 / AMD64)



Måns Rullgård <mans@xxxxxxxxx> wrote in
news:yw1x1vwz39z4.fsf@xxxxxxxxxxxxxxxxxxxx:

Carlos Moreno <cm_news@xxxxxxxxxxxxxx> writes:

uint128_t v1=0xFFFFFFFFFFFFFFFF, v2=0xFFFFFFFFFFFFFFFF;

const uint128_t p = static_cast<uint128_t>(v1) * v2;
cout << hex << *(reinterpret_cast<const uint64_t *>(&p)) << *
(reinterpret_cast<const uint64_t *>(&p) + 1) << endl;

The correct output is: 1fffffffffffffffe

And that's what it outputs with -O1 or below. When compiled with
-O2, the output is: 4009400

The C++ encryption might change things, but in C it is invalid to
access something through the "wrong" pointer type. In your case, you
are accessing a uint128_t using a uint64_t pointer, which violates
strict aliasing rules. If you compile this with -Wall, do you get a
warning about that? Does compiling with -fno-strict-aliasing produce
the expected result?

Måns is spot on:
Compiling with -Wstrict-aliasing (or -Wall) generates
"warning: dereferencing type-punned pointer will break strict-aliasing
rules".

And compiling with -fno-strict-aliasing causes the problem to go away.

GH
.



Relevant Pages

  • Installing openssh3.6.1p2 in solaris2.5 problem.
    ... I am trying to install openssh3.6.1p2 on a solaris 2.5 box. ... into lots problems when compiling it. ... I am running on a older version of gnu gcc. ...
    (SSH)
  • Re: Building Samba version 3.0.1 on OSR5.0.6
    ... > an Open Server 5.0.6 system. ... > Compiling client/client.c ... Roberto Zini - Technical Support Manager - email:r.zinistrhold.it ...
    (comp.unix.sco.misc)
  • Re: GCC bug? (4.2.4 on Ubuntu 8.04 / AMD64)
    ... access something through the "wrong" pointer type. ... strict aliasing rules. ... And compiling with -fno-strict-aliasing causes the problem to go away. ... Then your next task is to fix the code it doesn't need this flag. ...
    (comp.os.linux.development.apps)
  • Re: using long long
    ... Clark S. Cox III said: ... that you're compiling this code as C++, ... nice spot. ...
    (comp.lang.c)
  • Re: Latest on Indias objection to UDRS
    ... >> DRS could live very happily without Hot Spot. ... > Do you want me to start compiling a list of reviews where HotSpot ... Plus one decision overturned despite no evidence from Hot Spot. ...
    (rec.sport.cricket)