From 9d1a907345d6a04178b93389803e2d17f090953a Mon Sep 17 00:00:00 2001 From: Simon Hausmann Date: Wed, 23 May 2018 14:23:51 +0200 Subject: Fix QtScript on 64-bit systems with gcc 8 Similar to commit 92836d052efb6d8073136e8507083f93fb60bb80 in qtdeclarative, we must use memcpy to do a bit-wise conversion from the JSCell *m_ptr to an intptr_t for JSValue tag operations. This fixes the referenced task and all the failing auto-tests. The most visible result was that if ((jsvalue.immediateValue() & 0xffff000000000000ll) == 0xffff000000000000ll) return static_cast(jsvalue.immediateValue()); was "optimized" to "return 0", breaking QScriptValue::toNumber() for integer encoded values. [ChangeLog][QtScript] Fix incorrect script evaluations on 64-bit systems with gcc 8. Change-Id: I525b6b66d0e3c5163ad7e338fd0e866cdf620dad Task-number: QTBUG-68367 Reviewed-by: Lars Knoll Reviewed-by: Qt CI Bot --- .../javascriptcore/JavaScriptCore/runtime/JSValue.h | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/3rdparty/javascriptcore/JavaScriptCore/runtime/JSValue.h b/src/3rdparty/javascriptcore/JavaScriptCore/runtime/JSValue.h index 501ab5e..7584c52 100644 --- a/src/3rdparty/javascriptcore/JavaScriptCore/runtime/JSValue.h +++ b/src/3rdparty/javascriptcore/JavaScriptCore/runtime/JSValue.h @@ -773,22 +773,30 @@ namespace JSC { // JSValue member functions. inline EncodedJSValue JSValue::encode(JSValue value) { - return reinterpret_cast(value.m_ptr); + EncodedJSValue r; + memcpy(&r, &value.m_ptr, sizeof(r)); + return r; } inline JSValue JSValue::decode(EncodedJSValue ptr) { - return JSValue(reinterpret_cast(ptr)); + JSCell *cellPtr; + memcpy(&cellPtr, &ptr, sizeof(cellPtr)); + return JSValue(cellPtr); } inline JSValue JSValue::makeImmediate(intptr_t value) { - return JSValue(reinterpret_cast(value)); + JSCell *cellPtr; + memcpy(&cellPtr, &value, sizeof(cellPtr)); + return JSValue(cellPtr); } inline intptr_t JSValue::immediateValue() { - return reinterpret_cast(m_ptr); + intptr_t v; + memcpy(&v, &m_ptr, sizeof(v)); + return v; } // 0x0 can never occur naturally because it has a tag of 00, indicating a pointer value, but a payload of 0x0, which is in the (invalid) zero page. -- cgit v1.2.1