diff options
author | Ulf Hermann <ulf.hermann@qt.io> | 2022-03-01 08:44:28 +0100 |
---|---|---|
committer | Ulf Hermann <ulf.hermann@qt.io> | 2022-03-01 08:51:52 +0100 |
commit | 074b66e0073b55d32060ffd542a02c811ad763a8 (patch) | |
tree | c74d2a483fda29c1d98629f1194ff435d6d86b85 | |
parent | b81e27e65217f8425acb58c3ac848c728790c872 (diff) |
QmlCompiler: On MoveReg, check if we need to move at all
As we don't store void, null and empty lists, moving those is a noop.
Don't generate invalid code for that.
Pick-to: 6.2 6.3
Change-Id: Ica6714acd0ce8a5ddca44d9a397e776eb3df4247
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
-rw-r--r-- | src/qmlcompiler/qqmljscodegenerator.cpp | 2 | ||||
-rw-r--r-- | tests/auto/qml/qmlcppcodegen/data/CMakeLists.txt | 1 | ||||
-rw-r--r-- | tests/auto/qml/qmlcppcodegen/data/moveRegVoid.qml | 20 | ||||
-rw-r--r-- | tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp | 1 |
4 files changed, 24 insertions, 0 deletions
diff --git a/src/qmlcompiler/qqmljscodegenerator.cpp b/src/qmlcompiler/qqmljscodegenerator.cpp index 3847d52ed9..dba0ec82b2 100644 --- a/src/qmlcompiler/qqmljscodegenerator.cpp +++ b/src/qmlcompiler/qqmljscodegenerator.cpp @@ -593,6 +593,8 @@ void QQmlJSCodeGenerator::generate_MoveReg(int srcReg, int destReg) Q_ASSERT(m_state.changedRegisterIndex() == destReg); const QString destRegName = changedRegisterVariable(); m_body.setWriteRegister(destRegName); + if (destRegName.isEmpty()) + return; // don't store things we cannot store. m_body += destRegName; m_body += u" = "_qs; m_body += use(registerVariable(srcReg)); diff --git a/tests/auto/qml/qmlcppcodegen/data/CMakeLists.txt b/tests/auto/qml/qmlcppcodegen/data/CMakeLists.txt index 3e490bc9fc..7fa4bbde44 100644 --- a/tests/auto/qml/qmlcppcodegen/data/CMakeLists.txt +++ b/tests/auto/qml/qmlcppcodegen/data/CMakeLists.txt @@ -88,6 +88,7 @@ set(qml_files math.qml methods.qml modulePrefix.qml + moveRegVoid.qml noBindingLoop.qml noQQmlData.qml nonNotifyable.qml diff --git a/tests/auto/qml/qmlcppcodegen/data/moveRegVoid.qml b/tests/auto/qml/qmlcppcodegen/data/moveRegVoid.qml new file mode 100644 index 0000000000..f1e78babba --- /dev/null +++ b/tests/auto/qml/qmlcppcodegen/data/moveRegVoid.qml @@ -0,0 +1,20 @@ +import QtQuick + +Rectangle { + id: root + property bool translucency: false + + gradient: Gradient { + id: grad + } + + onTranslucencyChanged: { + if (translucency) { + root.color = "transparent"; + root.gradient = null; + } else { + root.color = "white"; + root.gradient = grad; + } + } +} diff --git a/tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp b/tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp index db30705efc..8d725a1ec8 100644 --- a/tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp +++ b/tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp @@ -655,6 +655,7 @@ void tst_QmlCppCodegen::interestingFiles_data() QTest::addRow("curlygrouped") << u"curlygrouped.qml"_qs << true; QTest::addRow("cycleHead") << u"cycleHead.qml"_qs << false; QTest::addRow("deadStoreLoop") << u"deadStoreLoop.qml"_qs << true; + QTest::addRow("moveRegVoid") << u"moveRegVoid.qml"_qs << true; } void tst_QmlCppCodegen::interestingFiles() |