diff options
author | Simon Hausmann <simon.hausmann@digia.com> | 2013-08-05 15:55:45 +0200 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2013-08-05 21:20:03 +0200 |
commit | 093f31330acf40a70681b0ff825987d6506f3f5e (patch) | |
tree | 82fd094e8d7ae18e290b9631d35e0b71e5ded32d /src/qml/qml/v4/qv4math_p.h | |
parent | d459eb7e3dda1caffc88673468353c237cd0615c (diff) |
Fix integer preserving arithmetics with the interpreter
This fixes qqmllanguage and some other auto-tests with the interpreter
When adding numbers, make sure to preserve them as integer if left and
right hand side are integers. We do this now consistently throughout
the runtime by providing fallback implementations of mul/sub/add_int32.
Change-Id: I37e24ce14dc676bb072571b57289965ec59999c1
Reviewed-by: Lars Knoll <lars.knoll@digia.com>
Diffstat (limited to 'src/qml/qml/v4/qv4math_p.h')
-rw-r--r-- | src/qml/qml/v4/qv4math_p.h | 39 |
1 files changed, 34 insertions, 5 deletions
diff --git a/src/qml/qml/v4/qv4math_p.h b/src/qml/qml/v4/qv4math_p.h index e0bb34895e..a3a3715545 100644 --- a/src/qml/qml/v4/qv4math_p.h +++ b/src/qml/qml/v4/qv4math_p.h @@ -41,22 +41,25 @@ #ifndef QMLJS_MATH_H #define QMLJS_MATH_H +#include <qglobal.h> + #ifndef QMLJS_LLVM_RUNTIME # include <QtCore/qnumeric.h> #endif // QMLJS_LLVM_RUNTIME #include <cmath> -#if !defined(QMLJS_LLVM_RUNTIME) && defined(Q_CC_GCC) && defined(Q_PROCESSOR_X86) -#define QMLJS_INLINE_MATH +#if defined(Q_CC_GNU) #define QMLJS_READONLY __attribute((const)) +#else +#define QMLJS_READONLY #endif -#if defined(QMLJS_INLINE_MATH) - QT_BEGIN_NAMESPACE namespace QV4 { +#if !defined(QMLJS_LLVM_RUNTIME) && defined(Q_CC_GNU) && defined(Q_PROCESSOR_X86) + static inline QMLJS_READONLY Value add_int32(int a, int b) { quint8 overflow = 0; @@ -105,12 +108,38 @@ static inline QMLJS_READONLY Value mul_int32(int a, int b) return Value::fromDouble((double)a * (double)b); } +#else + +static inline QMLJS_READONLY Value add_int32(int a, int b) +{ + qint64 result = a + b; + if (result > INT_MAX || result < INT_MIN) + return Value::fromDouble(result); + return Value::fromInt32(static_cast<int>(result)); } -QT_END_NAMESPACE +static inline QMLJS_READONLY Value sub_int32(int a, int b) +{ + qint64 result = a - b; + if (result > INT_MAX || result < INT_MIN) + return Value::fromDouble(result); + return Value::fromInt32(static_cast<int>(result)); +} + +static inline QMLJS_READONLY Value mul_int32(int a, int b) +{ + qint64 result = a * b; + if (result > INT_MAX || result < INT_MIN) + return Value::fromDouble(result); + return Value::fromInt32(static_cast<int>(result)); +} #endif // defined(QMLJS_INLINE_MATH) +} + +QT_END_NAMESPACE + #ifdef QMLJS_READONLY #undef QMLJS_READONLY #endif |