Project

General

Profile

Bug #13748

[PATCH] Fix mul overflow detection for LLP64 arch.

Added by larskanis (Lars Kanis) over 3 years ago. Updated about 3 years ago.

Status:
Closed
Priority:
Normal
Assignee:
-
Target version:
-
ruby -v:
ruby 2.5.0dev (2017-07-15 trunk 57962) [x64-mingw32]
[ruby-core:82077]

Description

FIXNUMs are expected to fit into a long type, but the test in MUL_OVERFLOW_FIXNUM_P() is about the VALUE type. Since long is smaller than VALUE on LLP64, the overflow is not detected. As an exemplary result "2**31" evaluates to "-2147483648" instead of "2147483648" on Windows when built with gcc-7.1.0.

This also results in many more test failures as described in this github issue: https://github.com/oneclick/rubyinstaller2/issues/55

gcc versions before 7.1.0 don't provide __builtin_mul_overflow_p() and ruby-2.4.x doesn't use this function, so that they don't show this broken behavior.

The attached patch fixes the issue. However I'm currently unable to run a full "make test-all" to verify whether this fixes all gcc-7.1.0 related issues.


Files

Also available in: Atom PDF