aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorUlf Hermann <ulf.hermann@qt.io>2022-02-18 12:31:54 +0100
committerQt Cherry-pick Bot <cherrypick_bot@qt-project.org>2022-02-21 07:19:16 +0000
commit02f9fd8af162532aae8554382ea41e135931a146 (patch)
tree656805b311a586510637b7f8ea47641c4e843779
parentcf284c869600d8b3d957f4a27bc7ba1dbf204f09 (diff)
QmlCompiler: Avoid infinite loop in dead store elimination
We have to mark the required variables also in block 0. And we shouldn't generate empty blocks. Fixes: QTBUG-101011 Change-Id: I0dd19f69f45f507cb83e2ddfba3060de48a940b4 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io> (cherry picked from commit 88147eb3f621e7d972410698d6edca16493d7c66) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
-rw-r--r--src/qmlcompiler/qqmljscodegenerator.cpp9
-rw-r--r--tests/auto/qml/qmlcppcodegen/data/CMakeLists.txt1
-rw-r--r--tests/auto/qml/qmlcppcodegen/data/deadStoreLoop.qml13
-rw-r--r--tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp1
4 files changed, 21 insertions, 3 deletions
diff --git a/src/qmlcompiler/qqmljscodegenerator.cpp b/src/qmlcompiler/qqmljscodegenerator.cpp
index 93b69474db..d87b2a38ad 100644
--- a/src/qmlcompiler/qqmljscodegenerator.cpp
+++ b/src/qmlcompiler/qqmljscodegenerator.cpp
@@ -184,9 +184,11 @@ QList<QQmlJSCodeGenerator::BasicBlock> QQmlJSCodeGenerator::findBasicBlocks(
const QQmlJSCodeGenerator::Section &section = sections[i];
const QString label = section.label();
if (!label.isEmpty() || currentBlock.jumpMode != JumpMode::None) {
- currentBlock.endSection = i;
- basicBlocks.append(currentBlock);
- currentBlock.beginSection = i;
+ if (currentBlock.beginSection != i) {
+ currentBlock.endSection = i;
+ basicBlocks.append(currentBlock);
+ currentBlock.beginSection = i;
+ }
currentBlock.label = label;
}
currentBlock.jumpMode = section.jumpMode();
@@ -320,6 +322,7 @@ void QQmlJSCodeGenerator::eliminateDeadStores()
usedOnce = true;
}
}
+ requiredRegisters[0][variable] = inUse;
if (!usedOnce) {
registerTypeIt = registerTypes.erase(registerTypeIt);
diff --git a/tests/auto/qml/qmlcppcodegen/data/CMakeLists.txt b/tests/auto/qml/qmlcppcodegen/data/CMakeLists.txt
index f51e72dcbd..791d34307f 100644
--- a/tests/auto/qml/qmlcppcodegen/data/CMakeLists.txt
+++ b/tests/auto/qml/qmlcppcodegen/data/CMakeLists.txt
@@ -49,6 +49,7 @@ set(qml_files
curlygrouped.qml
cycleHead.qml
deadShoeSize.qml
+ deadStoreLoop.qml
dialog.qml
dynamicscene.qml
enumInvalid.qml
diff --git a/tests/auto/qml/qmlcppcodegen/data/deadStoreLoop.qml b/tests/auto/qml/qmlcppcodegen/data/deadStoreLoop.qml
new file mode 100644
index 0000000000..f493e4b942
--- /dev/null
+++ b/tests/auto/qml/qmlcppcodegen/data/deadStoreLoop.qml
@@ -0,0 +1,13 @@
+import QtQuick
+import QtQuick.Controls.Basic
+
+Item {
+ Menu {
+ id: m
+ }
+ function c() {
+ while (m.count > 0) {
+ m.removeItem(m.itemAt(0))
+ }
+ }
+}
diff --git a/tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp b/tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp
index b04eb011b3..7c2fe38870 100644
--- a/tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp
+++ b/tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp
@@ -647,6 +647,7 @@ void tst_QmlCppCodegen::interestingFiles_data()
QTest::addRow("dynamicscene") << u"dynamicscene.qml"_qs << true;
QTest::addRow("curlygrouped") << u"curlygrouped.qml"_qs << true;
QTest::addRow("cycleHead") << u"cycleHead.qml"_qs << false;
+ QTest::addRow("deadStoreLoop") << u"deadStoreLoop.qml"_qs << true;
}
void tst_QmlCppCodegen::interestingFiles()