aboutsummaryrefslogtreecommitdiffstats
path: root/src/qmlcompiler/qqmljsbasicblocks_p.h
Commit message (Collapse)AuthorAgeFilesLines
* Add security header for src/qmlcompilerOlivier De Cannière2025-09-171-0/+1
| | | | | | | | | | | | | | | | | | We assume that QML or JS code comes from a trusted source. Therefore, most files are deemed to be significant even if they parse data. This includes the source code itself but also the associated metadata or cache files. However, the QML compiler also generates C++ code. Extra care needs to be taken with the generator as a vulnerability there could propagate and have a disproportionate effect on the program's security. It is marked as critical. QUIP: 23 Fixes: QTBUG-136195 Pick-to: 6.10 6.9 6.8 Change-Id: I70630361ec8e9cb3969f78a3fdf36a41334a33b3 Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
* QmlCompiler: Clean up error handlingUlf Hermann2025-02-021-3/+2
| | | | | | | | | | | | | | | | We should only have one way to handle diagnostic messages: The QQmlJSLogger. In addition each compile pass may result in an error that prevents the running of further passes. But that error should not rely on the selection of messages posted earlier. For this to work we need to introduce a further state transition into the logger. The logger now "archives" messages after compiling each function, so that only the current function's compile errors are taken into account as result of the current function's compilation. Task-number: QTBUG-124913 Change-Id: I4b6d9910b80527cefb1aba02598114d1fe5ba172 Reviewed-by: Olivier De Cannière <olivier.decanniere@qt.io>
* Compiler: Create infrastructure to support multiple warningsOlivier De Cannière2024-08-211-2/+3
| | | | | | | | | | | | | | | | | Currently only one DiagnosticMessage can be stored at a time when using the compiler. However, we want to be able to show more than one to the user. Therefore, use a list that gets passed inside the compiler instead of a pointer to the sole error. This also means that the error is valid by its very existence. There is no need to check validity explicitly anymore. Task-number: QTBUG-127624 Change-Id: I356db917b86703b508dc1ad52de7825d82eafd71 Reviewed-by: Ulf Hermann <ulf.hermann@qt.io> Reviewed-by: Sami Shalayel <sami.shalayel@qt.io>
* Compiler: Extract Basic blocks generation into its own compiler passOlivier De Cannière2024-04-191-47/+9
| | | | | | | | | | | | | | | The old basic blocks pass was responsible for two things: the basic blocks generation and dead code analysis/type adjustments based on those blocks and the type propagation performed earlier. Now the basic blocks get generated first, even before the type propagation and the dead code analysis and type adjustments are now grouped in a pass called QQmlJSOptimizations. The rest of the passes remain unchanged. Change-Id: I7b4303eaf67c761a49b82ab194e5d035d24d2615 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io> Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
* QmlCompiler: Use a hash set for the list of conversionsUlf Hermann2024-01-201-1/+3
| | | | | | | | | | | | There can be a lot of them and we don't want quadratic behavior. It might be possible to further improve on this using e.g. sorted lists and algorithms provided by the STL. However, such an implementation would be more complicated and would require weighing several trade-offs. Pick-to: 6.7 6.6 6.5 Fixes: QTBUG-121139 Change-Id: I717b49bd4af97abcaae9ae78d1e1b31d5d462952 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io> Reviewed-by: Marc Mutz <marc.mutz@qt.io>
* Remove the use of Q_QMLCOMPILER_PRIVATE_EXPORTAlexey Edelev2024-01-091-1/+1
| | | | | | Task-number: QTBUG-117983 Change-Id: I893ba2a6c83af92d65d843b6a37bb14c6c1e45bf Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
* Compiler: Add initial support for optional chainingOlivier De Cannière2023-11-241-0/+1
| | | | | | | | | | This patch implements the GetOptionalLookup instruction in the compiler. This enables the use of optional chains. Fixes: QTBUG-111283 Change-Id: I265f611415a946468b828b9d41f549acfcc76233 Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* QmlCompiler: Implement GetIterator and IteratorNextUlf Hermann2023-09-211-0/+1
| | | | | | | | | | | | | | | | | | | | | | | | Each GetIterator generates * A unique iterator variable that keeps track of the current index * In the case of for...of a copy of reference to the list being iterated The result register holds a pointer to the unique iterator so that it can be loaded and stored without resetting it. In order to do anything meaningful with iterators (in the tests) we also need to allow LoadElement with our "optional" types. That is a conversion of undefined and some other type to QVariant or QJSPrimitiveValue. This follows the same pattern as the other "optional"s we already have. For...of is currently not testable because it requires exception handlers. The tests will be added once we get exception handlers. Task-number: QTBUG-116725 Change-Id: I167fe16b983dc34bf86e1840dfcbf2bf682eecc1 Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* QmlCompiler: Allow construction of Array objectsUlf Hermann2023-08-221-2/+6
| | | | | | | | | | Currently, only the constructor form of the Array function is compiled. We only compile construction of Array objects if we can determine that they are immediately assigned to a typed list. Consequently, we don't have to deal with sparse arrays. Change-Id: I2abd15139eb9a0d530ad49df7313b8dba415ae77 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* Compiler: Separate function prolog block and add validation of blocksOlivier De Cannière2023-08-041-4/+15
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The function prolog logic is now separated in its own basic block. The first "real" block with user code starts at offset 0. Having the function prolog as a hidden part of the first block caused some inconsistencies in block generation and would create empty blocks. This happened for example when a back edge of a loop would target offset 0 in code where a loop condition is the very first set of instructions that are run. This is because the target block offset didn't exist due to it being part of the hidden prolog block. Validation for the basic blocks was also added. This checks for three things at the moment: 1. That return and throw blocks don't have jump targets. 2. That the basic blocks graph is connected. 3. That jump targets are the first offset of a block. Test tst_QmlCppCodegen::basicBlocksWithBackJump_infinite() is expected to fail because it contains an infinite loop and the basic blocks that are generated for it are inconsistent due to dead-code elimination happening earlier in compilation. Debug outputs for dumping basic blocks were also adapted to reflect these changes. Change-Id: I513f73856412d488d443c2b47a052b0023d45496 Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* Compiler: Allow dumping the basic blocks for visualization and debuggingOlivier De Cannière2023-07-101-2/+7
| | | | | | | | | | | | | | | | | | | | If the QV4_DUMP_BASIC_BLOCKS environment variable is set, the compiler will output the details of the basic blocks of the compiled functions to the console. It will also generate a control flow graph containing the byte code in DOT format for easier visualization and debugging of the program execution and of the structure of the generated code. The value of QV4_DUMP_BASIC_BLOCKS will be used as the path to the folder in which to output the DOT files. If the path is any of ["-", "1", "true"] or if files can't be opened, it will be dumped to stdout instead. The logic in dumpByteCode has been adapted to use a QTextStream. This way it can continue to be used to dump the byte code of the whole program as before and also to construct the CFG. Change-Id: If398d795e4fc0950b5fa8ee1349e80b1ae262deb Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
* QmlCompiler: Allow creation of structured value typesUlf Hermann2023-07-061-1/+12
| | | | | | | | | | | | | | | | With this change, qmlcachegen can populate structured value types from object literals. Also fix the construction of value types via Q_INVOKABLE ctors. We don't need to wrap the ctor argument in QVariant if we can store the original type, and we should always look at the base type for the creatable flag, not the extension. Task-number: QTBUG-107469 Task-number: QTBUG-112485 Change-Id: I9f3db13f00466dc9d87237bdf0b380d6eeb58a10 Reviewed-by: Sami Shalayel <sami.shalayel@qt.io> Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* QmlCompiler: Enforce sanity of type adjustments in basic blocks passUlf Hermann2023-03-111-1/+3
| | | | | | | | | | | | If we cannot properly adjust the types, the result will probably be garbage and we should not try to generate any code. We are double checking the actually received type in the code generator, but if we get a different type at code generation time than we "ordered" at type propagation time, that's not great. The type propagator should already have checked that the types are convertible, after all. Change-Id: I9c20dbd6b4cc8214e780dad9eb4302ca6ef81bac Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* QmlCompiler: std::move() registers where possibleUlf Hermann2022-12-231-0/+1
| | | | | | | | | | | | In the common case that we read a register only once, in the same basic block, generate a std::move() in order to move it into place. Especially for QVariants holding large internal objects, this should help performance. Fixes: QTBUG-101452 Change-Id: I015892e1046ca7b739dbd296756f3f012dba5f9b Reviewed-by: Sami Shalayel <sami.shalayel@qt.io>
* QmlCompiler: Fix register propagation in basic blocks passUlf Hermann2022-07-051-1/+0
| | | | | | | | | | | | | a, We were recording too many jump origins and targets. That messed up the basic blocks ordering logic. b, In the presence of backward jumps, we need to revisit earlier basic blocks if additional writes are discovered. Otherwise the type adjustment will optimize "dead" type conversions out. Pick-to: 6.4 Fixes: QTBUG-104665 Change-Id: I7219f85625761817ae4f63582d80d247a85df73b Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* Use SPDX license identifiersLucie Gérard2022-06-111-27/+2
| | | | | | | | | | | | Replace the current license disclaimer in files by a SPDX-License-Identifier. Files that have to be modified by hand are modified. License files are organized under LICENSES directory. Pick-to: 6.4 Task-number: QTBUG-67283 Change-Id: I63563bbeb6f60f89d2c99660400dca7fab78a294 Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
* QmlCompiler: Clean up exportsUlf Hermann2022-03-301-1/+1
| | | | | | | | We need to export all the classes used by qmlsc, and we need to use the private export macro for private symbols. Change-Id: I91d59611e864621dc2c49b9383596e706529bd42 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* QmlCompiler: Implement generate_DefineArrayUlf Hermann2022-03-141-0/+3
| | | | | | | | | | | Using the type cloning and adaption mechanism we can now determine what kind of list we have to create in order to avoid a later conversion. We can even propagate the type adjustment into the element types we read. Fixes: QTBUG-100157 Change-Id: Ia2f160ebae56f39ee5946f49d2f8c5b4986a6b77 Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* QmlCompiler: Add register tracking to basic blocks passUlf Hermann2022-03-121-2/+6
| | | | | | | | This way we can detect dead LoadReg and StoreReg instructions. This is a precondition to removing the basic blocks pass in the code generator. Change-Id: Iab1ed60c1aa56a15935a35507f5ac67292aa56b3 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* QmlCompiler: Add basic block analysis passUlf Hermann2022-03-091-0/+102
This basic block analysis pass uses the tracked types to determine dead stores. This is better than the one we already have in the code generator because it also tracks dead stores through renames and it allows removal of lookup results. Furthermore, it adjusts each store to write the type most favorable to its readers. This avoids unnecessary conversions at run time. It cannot replace the other dead store elimination, yet, because it doesn't see whether the results of rename operations are read after the rename. This capability will be added in a separate change that also tracks the register numbers. Once this is in place, we can delete the other basic blocks pass. Task-number: QTBUG-100157 Change-Id: I766c919412b6cf43befa7bdb1a6e5e11b41fe55b Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>