LibRegex: Treat backwards jumps to IP 0 as normal backwards jumps too
This shows up in something like /\d+|x/, where the `+` ends up jumping to the start of its own alternative.
This commit is contained in:
parent
045880e6c7
commit
4d27257c45
Notes:
sideshowbarker
2024-07-17 06:20:50 +09:00
Author: https://github.com/alimpfard Commit: https://github.com/SerenityOS/serenity/commit/4d27257c45 Pull-request: https://github.com/SerenityOS/serenity/pull/20602 Reviewed-by: https://github.com/gmta ✅
2 changed files with 3 additions and 1 deletions
|
@ -1051,6 +1051,8 @@ TEST_CASE(optimizer_alternation)
|
|||
Tuple { "ab|ac|ad|bc"sv, "bc"sv, 2u },
|
||||
// Should not crash on backwards jumps introduced by '.*'.
|
||||
Tuple { "\\bDroid\\b.*Build|XT912|XT928|XT926|XT915|XT919|XT925|XT1021|\\bMoto E\\b|XT1068|XT1092|XT1052"sv, "XT1068"sv, 6u },
|
||||
// Backwards jumps to IP 0 are normal jumps too.
|
||||
Tuple { "^(\\d+|x)"sv, "42"sv, 2u },
|
||||
};
|
||||
|
||||
for (auto& test : tests) {
|
||||
|
|
|
@ -1150,7 +1150,7 @@ void Optimizer::append_alternation(ByteCode& target, Span<ByteCode> alternatives
|
|||
VERIFY(node->has_metadata());
|
||||
QualifiedIP ip = node->metadata_value().first();
|
||||
auto intended_jump_ip = ip.instruction_position + jump_offset + opcode.size();
|
||||
if (jump_offset < 0 && intended_jump_ip > 0) {
|
||||
if (jump_offset < 0) {
|
||||
VERIFY(has_any_backwards_jump);
|
||||
// We should've already seen this instruction, so we can just patch it in.
|
||||
auto& ip_mapping = ip_mapping_for_alternative(ip.alternative_index);
|
||||
|
|
Loading…
Add table
Reference in a new issue