Project

General

Profile

Bug #13545

Ruby built by clang 4.0.0 parses Float literal wrongly

Added by mame (Yusuke Endoh) over 2 years ago. Updated over 2 years ago.

Status:
Closed
Priority:
Normal
Assignee:
-
Target version:
-
[ruby-core:81003]

Description

$ ./configure --prefix=/home/mame/work/local CC=clang
$ make -j 4 miniruby
$ ./miniruby -e 'p 1.1851510441583988e+30'
1.1851510441583981e+30

See the last digit. While the original literal ends with "8e+30", the result ends with "1e+30". The version of clang is 4.0.0-1ubuntu1.

There seems to be a bug in ruby_strtod. It manipulates a double variable as an integer variable by using cast. I think that this is undefined behavior, and clang seems to optimize some operations out.

We can fix this issue by adding volatile to its variable declaration, but I'm unsure if this is a good solution.

diff --git a/util.c b/util.c
index 4ae7c4fc96..ecd55bb0c5 100644
--- a/util.c
+++ b/util.c
@@ -1832,7 +1832,7 @@ d2b(double d_, int *e, int *bits)
 static double
 ratio(Bigint *a, Bigint *b)
 {
-    double_u da, db;
+    volatile double_u da, db;
     int k, ka, kb;

     dval(da) = b2d(a, &ka);

Associated revisions

Revision 7be47caa
Added by naruse (Yui NARUSE) over 2 years ago

Merge latest dtoa.c [Bug #13545]

Apply some part of http://www.netlib.org/fp/dtoa.c with my eyes...

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58796 b2dd03c8-39d4-4d8f-98ff-823fe69b080e

Revision 58796
Added by naruse (Yui NARUSE) over 2 years ago

Merge latest dtoa.c [Bug #13545]

Apply some part of http://www.netlib.org/fp/dtoa.c with my eyes...

Revision 58796
Added by naruse (Yui NARUSE) over 2 years ago

Merge latest dtoa.c [Bug #13545]

Apply some part of http://www.netlib.org/fp/dtoa.c with my eyes...

Revision 58796
Added by naruse (Yui NARUSE) over 2 years ago

Merge latest dtoa.c [Bug #13545]

Apply some part of http://www.netlib.org/fp/dtoa.c with my eyes...

Revision d058c8a2
Added by usa (Usaku NAKAMURA) over 2 years ago

merge revision(s) 58796: [Backport #13545]

    Merge latest dtoa.c [Bug #13545]

    Apply some part of http://www.netlib.org/fp/dtoa.c with my eyes...

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_3@59224 b2dd03c8-39d4-4d8f-98ff-823fe69b080e

Revision 59224
Added by usa (Usaku NAKAMURA) over 2 years ago

merge revision(s) 58796: [Backport #13545]

Merge latest dtoa.c [Bug #13545]

Apply some part of http://www.netlib.org/fp/dtoa.c with my eyes...

Revision c54593ed
Added by nagachika (Tomoyuki Chikanaga) over 2 years ago

merge revision(s) 58796: [Backport #13545]

    Merge latest dtoa.c [Bug #13545]

    Apply some part of http://www.netlib.org/fp/dtoa.c with my eyes...

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_4@59298 b2dd03c8-39d4-4d8f-98ff-823fe69b080e

Revision 59298
Added by nagachika (Tomoyuki Chikanaga) over 2 years ago

merge revision(s) 58796: [Backport #13545]

Merge latest dtoa.c [Bug #13545]

Apply some part of http://www.netlib.org/fp/dtoa.c with my eyes...

History

#1

Updated by naruse (Yui NARUSE) over 2 years ago

  • Status changed from Open to Closed

Applied in changeset trunk|r58796.


Merge latest dtoa.c [Bug #13545]

Apply some part of http://www.netlib.org/fp/dtoa.c with my eyes...

#2

Updated by naruse (Yui NARUSE) over 2 years ago

  • Backport changed from 2.2: UNKNOWN, 2.3: UNKNOWN, 2.4: UNKNOWN to 2.2: REQUIRED, 2.3: REQUIRED, 2.4: REQUIRED

Updated by usa (Usaku NAKAMURA) over 2 years ago

  • Backport changed from 2.2: REQUIRED, 2.3: REQUIRED, 2.4: REQUIRED to 2.2: REQUIRED, 2.3: DONE, 2.4: REQUIRED

ruby_2_3 r59224 merged revision(s) 58796.

Updated by nagachika (Tomoyuki Chikanaga) over 2 years ago

  • Backport changed from 2.2: REQUIRED, 2.3: DONE, 2.4: REQUIRED to 2.2: REQUIRED, 2.3: DONE, 2.4: DONE

ruby_2_4 r59298 merged revision(s) 58796.

Also available in: Atom PDF