diff options
| author | Ulf Hermann <ulf.hermann@qt.io> | 2025-06-26 12:37:56 +0200 |
|---|---|---|
| committer | Ulf Hermann <ulf.hermann@qt.io> | 2025-06-27 21:56:31 +0200 |
| commit | b9974d82cd134b51bd1833c3e62c7345c8ea2962 (patch) | |
| tree | 9ec0ca62812dd11d388cd70473015ec6734eb074 /tests/auto/qml/qmlcppcodegen | |
| parent | b1bdad8096a45098d6ac668142493cccfd019579 (diff) | |
QmlCompiler: Preserve external side effects across jumps
Now that we discern internal and external side effects, we cannot
implicitly rely on every jump to generate a side effect anymore. We need
to actually update the virtual registers and also merge the side effects
(along with other flags).
Amends commit 6b14ba5c2fbc2810bb62a87008e338cca571acf6
Pick-to: 6.10 6.9 6.8 6.5
Task-number: QTBUG-137540
Change-Id: I6b46c7a4773759c8f6f30308ba72082555ce3e61
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Reviewed-by: Olivier De Cannière <olivier.decanniere@qt.io>
Diffstat (limited to 'tests/auto/qml/qmlcppcodegen')
| -rw-r--r-- | tests/auto/qml/qmlcppcodegen/data/CMakeLists.txt | 1 | ||||
| -rw-r--r-- | tests/auto/qml/qmlcppcodegen/data/mergeSideEffects.qml | 20 | ||||
| -rw-r--r-- | tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp | 11 |
3 files changed, 32 insertions, 0 deletions
diff --git a/tests/auto/qml/qmlcppcodegen/data/CMakeLists.txt b/tests/auto/qml/qmlcppcodegen/data/CMakeLists.txt index 36fb7ab01b..dd5dc3ab73 100644 --- a/tests/auto/qml/qmlcppcodegen/data/CMakeLists.txt +++ b/tests/auto/qml/qmlcppcodegen/data/CMakeLists.txt @@ -223,6 +223,7 @@ set(qml_files mathMinMax.qml mathOperations.qml mathStaticProperties.qml + mergeSideEffects.qml mergedObjectRead.qml mergedObjectWrite.qml methodOnListLookup.qml diff --git a/tests/auto/qml/qmlcppcodegen/data/mergeSideEffects.qml b/tests/auto/qml/qmlcppcodegen/data/mergeSideEffects.qml new file mode 100644 index 0000000000..d4a8fec42e --- /dev/null +++ b/tests/auto/qml/qmlcppcodegen/data/mergeSideEffects.qml @@ -0,0 +1,20 @@ +import QtQml + +QtObject { + property bool no: false + property list<int> a: [1] + property list<int> b: [2] + + property int c: { + let numbers = a; + a = [3]; // create side effect affecting "numbers" + + if (no) { + // Force two branches to be merged on "numbers" + numbers = b + } + + // Side effect is still in effect + return numbers[0]; + } +} diff --git a/tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp b/tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp index 00c00b4c0f..39292d9dd8 100644 --- a/tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp +++ b/tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp @@ -184,6 +184,7 @@ private slots: void mathMinMax(); void mathOperations(); void mathStaticProperties(); + void mergeSideEffects(); void mergedObjectReadWrite(); void methodOnListLookup(); void methods(); @@ -3712,6 +3713,16 @@ void tst_QmlCppCodegen::mathStaticProperties() QCOMPARE(object->property("sqrt2").toDouble(), 1.4142135623730951); } +void tst_QmlCppCodegen::mergeSideEffects() +{ + QQmlEngine engine; + QQmlComponent c(&engine, QUrl(u"qrc:/qt/qml/TestTypes/mergeSideEffects.qml"_s)); + QVERIFY2(c.isReady(), qPrintable(c.errorString())); + QScopedPointer<QObject> o(c.create()); + QVERIFY(!o.isNull()); + QCOMPARE(o->property("c").toInt(), 3); +} + void tst_QmlCppCodegen::mergedObjectReadWrite() { QQmlEngine e; |
