Skip to content

Instantly share code, notes, and snippets.

@kimuraw
Created July 12, 2012 13:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kimuraw/3098244 to your computer and use it in GitHub Desktop.
Save kimuraw/3098244 to your computer and use it in GitHub Desktop.
fix: ruby-1.8.7 built with clang "-Os". bignum does not pass sample/test.rb.
Index: numeric.c
===================================================================
--- numeric.c (revision 36354)
+++ numeric.c (working copy)
@@ -2161,7 +2161,7 @@
VALUE x, y;
{
if (FIXNUM_P(y)) {
-#ifdef __HP_cc
+#if defined(__HP_cc) || defined(__clang__)
/* avoids an optimization bug of HP aC++/ANSI C B3910B A.06.05 [Jul 25 2005] */
volatile
#endif
@@ -2319,9 +2319,9 @@
y &= ~1;
do {
while (y % 2 == 0) {
- long x2 = x * x;
+ volatile long x2 = x * x;
if (x2/x != x || !POSFIXABLE(x2)) {
- VALUE v;
+ volatile VALUE v;
bignum:
v = rb_big_pow(rb_int2big(x), LONG2NUM(y));
if (z != 1) v = rb_big_mul(rb_int2big(neg ? -z : z), v);
@@ -2331,7 +2331,7 @@
y >>= 1;
}
{
- long xz = x * z;
+ volatile long xz = x * z;
if (!POSFIXABLE(xz) || xz / x != z) {
goto bignum;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment