aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto/qml/qmlcppcodegen/data/javaScriptArgument.qml
diff options
context:
space:
mode:
authorUlf Hermann <ulf.hermann@qt.io>2022-06-20 14:44:35 +0200
committerUlf Hermann <ulf.hermann@qt.io>2022-06-23 09:35:57 +0200
commit6a0ab2e8aa0bcc2487ae895033b493a9e4d7704b (patch)
tree42f6cdc758868d9c1f328b4fb20e9000fff15f84 /tests/auto/qml/qmlcppcodegen/data/javaScriptArgument.qml
parent87f984714408bb5112fb38a66f0280b722ac9491 (diff)
QmlCompiler: Fix miscompilation if arguments are overwritten
In that case we need to allocate extra registers. We already did so before, but we wouldn't use the registers afterwards. This works nicely in 6.4 because we have a separate type for each store operation. Therefore, the original function argument (being of a different "type") won't be found in the list of local registers. Access to it falls back on the actual arguments array. Only once we've stored something into the register that mirrors the argument we can retrieve it. Pick-to: 6.4 Fixes: QTBUG-104462 Change-Id: Ibb0315cd2f8a8e4106d39fff88a6097b1623eb48 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Diffstat (limited to 'tests/auto/qml/qmlcppcodegen/data/javaScriptArgument.qml')
-rw-r--r--tests/auto/qml/qmlcppcodegen/data/javaScriptArgument.qml34
1 files changed, 34 insertions, 0 deletions
diff --git a/tests/auto/qml/qmlcppcodegen/data/javaScriptArgument.qml b/tests/auto/qml/qmlcppcodegen/data/javaScriptArgument.qml
new file mode 100644
index 0000000000..870540240e
--- /dev/null
+++ b/tests/auto/qml/qmlcppcodegen/data/javaScriptArgument.qml
@@ -0,0 +1,34 @@
+pragma Strict
+import QtQml
+
+QtObject {
+ function absMinusOne(amount: real) : real {
+ // Access it before the condition below, to make sure we still get the original
+ var minusOne = amount !== 0 ? -1 : 0;
+
+ // The condition causes the original arguemnt to be overwritten rather than a new
+ // register to be allocated
+ if (amount < 0)
+ amount = -amount;
+
+ return amount + minusOne;
+ }
+
+ property real a: absMinusOne(-5)
+ property real b: absMinusOne(10)
+
+ function stringMinusOne(amount: real) : string {
+ // Access it before the condition below, to make sure we still get the original
+ var minusOne = amount !== 0 ? -1 : 0;
+
+ // The condition causes the original arguemnt to be overwritten rather than a new
+ // register to be allocated
+ if (amount < 0)
+ amount = -amount + "t";
+
+ return amount + minusOne;
+ }
+
+ property string c: stringMinusOne(-5)
+ property string d: stringMinusOne(10)
+}