summaryrefslogtreecommitdiff
path: root/src/qml/compiler/qv4bytecodegenerator.cpp
diff options
context:
space:
mode:
authorSimon Hausmann <simon.hausmann@qt.io>2018-01-05 15:49:19 +0100
committerSimon Hausmann <simon.hausmann@qt.io>2018-01-07 20:14:45 +0000
commit8d83267dced1b36145421ae1bf5eee6209400d76 (patch)
tree54b95c3a8efed8556438009f0b65e72ae66836cd /src/qml/compiler/qv4bytecodegenerator.cpp
parentd1e7e5cd7d5eb601541dcc4860ce11a63048d35d (diff)
downloadqtdeclarative-8d83267dced1b36145421ae1bf5eee6209400d76.tar.gz
Prospective fix for big endian and AOT
Ensure that the integer arguments for widely encoded instructions are always encoded as little endian. Change-Id: Iccd45aefb20b20d76fe1618d6706435142b202b9 Reviewed-by: Lars Knoll <lars.knoll@qt.io>
Diffstat (limited to 'src/qml/compiler/qv4bytecodegenerator.cpp')
-rw-r--r--src/qml/compiler/qv4bytecodegenerator.cpp16
1 files changed, 12 insertions, 4 deletions
diff --git a/src/qml/compiler/qv4bytecodegenerator.cpp b/src/qml/compiler/qv4bytecodegenerator.cpp
index 0becabe95f..efa4b36f05 100644
--- a/src/qml/compiler/qv4bytecodegenerator.cpp
+++ b/src/qml/compiler/qv4bytecodegenerator.cpp
@@ -76,7 +76,9 @@ void BytecodeGenerator::packInstruction(I &i)
type -= MOTH_NUM_INSTRUCTIONS();
int instructionsAsInts[sizeof(Instr)/sizeof(int)];
int nMembers = Moth::InstrInfo::argumentCount[static_cast<int>(i.type)];
- memcpy(instructionsAsInts, i.packed + 1, nMembers*sizeof(int));
+ for (int j = 0; j < nMembers; ++j) {
+ instructionsAsInts[j] = qFromLittleEndian<qint32>(i.packed + 1 + j * sizeof(int));
+ }
enum {
Normal,
Wide
@@ -122,7 +124,7 @@ void BytecodeGenerator::adjustJumpOffsets()
uchar type = *reinterpret_cast<const uchar *>(i.packed);
if (type >= MOTH_NUM_INSTRUCTIONS()) {
Q_ASSERT(i.offsetForJump == i.size - 4);
- memcpy(c, &jumpOffset, sizeof(int));
+ qToLittleEndian<qint32>(jumpOffset, c);
} else {
Q_ASSERT(i.offsetForJump == i.size - 1);
qint8 o = jumpOffset;
@@ -198,7 +200,8 @@ QT_WARNING_POP
const int pos = instructions.size();
- int s = Moth::InstrInfo::argumentCount[static_cast<int>(type)]*sizeof(int);
+ const int argCount = Moth::InstrInfo::argumentCount[static_cast<int>(type)];
+ int s = argCount*sizeof(int);
if (offsetOfOffset != -1)
offsetOfOffset += 1;
I instr{type, static_cast<short>(s + 1), 0, currentLine, offsetOfOffset, -1, "\0\0" };
@@ -206,7 +209,12 @@ QT_WARNING_POP
*reinterpret_cast<uchar *>(code) = static_cast<uchar>(MOTH_NUM_INSTRUCTIONS() + static_cast<int>(type));
++code;
Q_ASSERT(MOTH_NUM_INSTRUCTIONS() + static_cast<int>(type) < 256);
- memcpy(code, &i, s);
+
+ for (int j = 0; j < argCount; ++j) {
+ qToLittleEndian<qint32>(i.argumentsAsInts[j], code);
+ code += sizeof(int);
+ }
+
instructions.append(instr);
return pos;