Status: New
Owner: ----

New issue 266 by [email protected]: Fix strict aliasing problems in  
v8/src/third_party/dtoa/dtoa.c
http://code.google.com/p/v8/issues/detail?id=266

I'm a programmer maintaining a copy of dtoa.c in Mozilla Firefox.
(Firefox has two copies of dtoa.c, one in the NSPR component, the
other in the JavaScript component.)

Recently we found that, when compiling dtoa.c with GCC 4.4 at
optimization level -O2 or higher, our dtoa.c tests fail.  This is
because the word0, word1, and dval macros (YES_ALIAS) added to
dtoa.c at Fri Sep 17 01:39:25 EDT 1999 are still considered to
violate strict aliasing rules by the latest versions of GCC.  It
is described in the GCC manual in the third code snippet under
-fstrict-aliasing:
http://gcc.gnu.org/onlinedocs/gcc-4.3.3/gcc/Optimize-Options.html#index-
fstrict_002daliasing-721

I am now working around this by compiling our copy of dtoa.c with
GCC's -fno-strict-aliasing flag.  The attached files are my attempt
at a real fix, which I sent to the author of dtoa.c last Thursday:
- dtoa-aliasing-patch.txt: a patch for the current version of dtoa.c
- dtoa-no-alias.c: the current version of dtoa.c with the above
   patch applied

I tried to minimize the diffs to make the patch easier to review.
I used the following strategy when preparing the patch:

1. Use the dval, word0, and word1 macros only on variables of
type U (the union).  Do not use these macros on doubles.

2. Functions that take a double parameter or return a double
value continue to do so.  I didn't change the parameter or
return value to type U.  Instead, I rename a double parameter
by prepending 'd' and the original double parameter becomes a
local variable of type U.  For example, a double parameter 'x'
would be renamed 'dx', and I declare 'x' as a local variable of
type U and initialize 'x' with 'dx':

  void foo(double dx)  /* dx used to be named x */
  {
      U x;

      dval(x) = dx;

The only exception is hexnan and gethex.  I changed their
double *rvp parameters to U *rvp because the argument we
pass to hexnan and gethex (&rv) has been changed to type U.

3. In strtod, the double variable aadj1 is used "naked" in a
lot of places, and is only passed to those three macros once
(specifically, word0(aadj1)).  If I redeclare aadj1 as type U,
I'll need to use macros on a lot of places.  So instead, I just
use a local variable 'temp' to deal with the single instance
of word0(aadj1).

4. The Storeinc macro also has aliasing problems.  Since it
is used only if NO_LONG_LONG is defined, and today 'long long'
is widely available, I didn't bother to fix Storeinc.

You can find more info about this bug in these bug reports:
https://bugzilla.redhat.com/show_bug.cgi?id=487844
https://bugzilla.mozilla.org/show_bug.cgi?id=439144
https://bugzilla.mozilla.org/show_bug.cgi?id=450392

Attachments:
        dtoa-aliasing-patch.txt  6.8 KB
        dtoa.c.no-alias  77.7 KB

--
You received this message because you are listed in the owner
or CC fields of this issue, or because you starred this issue.
You may adjust your issue notification preferences at:
http://code.google.com/hosting/settings

--~--~---------~--~----~------------~-------~--~----~
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
-~----------~----~----~----~------~----~------~--~---

Reply via email to