Skip to content

Commit c361a62

Browse files
pthiertargos
authored andcommitted
deps: V8: cherry-pick 72b0e27bd936
Original commit message: [regexp] Fix modifiers for ChoiceNodes Each alternative might modify flags when their sub-graph is emitted. We need to restore flags to the value at the beginning of a ChoiceNode for each alternative. Drive-by: Move regexp-modifiers test out of harmony/ Fixed: 447583670 Change-Id: I9f41e51f34df7659461da0a4fcd28b7e157f52e1 Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/6995181 Reviewed-by: Jakob Linke <jgruber@chromium.org> Commit-Queue: Patrick Thier <pthier@chromium.org> Cr-Commit-Position: refs/heads/main@{#102838} Refs: v8/v8@72b0e27 Fixes: #60030 PR-URL: #60732 Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com>
1 parent c70f458 commit c361a62

File tree

4 files changed

+19
-8
lines changed

4 files changed

+19
-8
lines changed

common.gypi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838

3939
# Reset this number to 0 on major V8 upgrades.
4040
# Increment by one for each non-official patch applied to deps/v8.
41-
'v8_embedder_string': '-node.36',
41+
'v8_embedder_string': '-node.37',
4242

4343
##### V8 defaults for Node.js #####
4444

deps/v8/src/regexp/regexp-compiler.cc

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3220,20 +3220,25 @@ void ChoiceNode::Emit(RegExpCompiler* compiler, Trace* trace) {
32203220
int text_length = FixedLengthLoopLengthForAlternative(&alternatives_->at(0));
32213221
AlternativeGenerationList alt_gens(choice_count, zone());
32223222

3223+
// Flags need to be reset to the state of the ChoiceNode at the beginning
3224+
// of each alternative (in-line and out-of-line), as flags might be modified
3225+
// when emitting an alternative.
3226+
RegExpFlags flags = compiler->flags();
32233227
if (choice_count > 1 && text_length != kNodeIsTooComplexForFixedLengthLoops) {
32243228
trace = EmitFixedLengthLoop(compiler, trace, &alt_gens, &preload,
3225-
&fixed_length_loop_state, text_length);
3229+
&fixed_length_loop_state, text_length, flags);
32263230
} else {
32273231
preload.eats_at_least_ = EmitOptimizedUnanchoredSearch(compiler, trace);
32283232

3229-
EmitChoices(compiler, &alt_gens, 0, trace, &preload);
3233+
EmitChoices(compiler, &alt_gens, 0, trace, &preload, flags);
32303234
}
32313235

32323236
// At this point we need to generate slow checks for the alternatives where
32333237
// the quick check was inlined. We can recognize these because the associated
32343238
// label was bound.
32353239
int new_flush_budget = trace->flush_budget() / choice_count;
32363240
for (int i = 0; i < choice_count; i++) {
3241+
compiler->set_flags(flags);
32373242
AlternativeGeneration* alt_gen = alt_gens.at(i);
32383243
Trace new_trace(*trace);
32393244
// If there are actions to be flushed we have to limit how many times
@@ -3253,7 +3258,7 @@ void ChoiceNode::Emit(RegExpCompiler* compiler, Trace* trace) {
32533258
Trace* ChoiceNode::EmitFixedLengthLoop(
32543259
RegExpCompiler* compiler, Trace* trace, AlternativeGenerationList* alt_gens,
32553260
PreloadState* preload, FixedLengthLoopState* fixed_length_loop_state,
3256-
int text_length) {
3261+
int text_length, RegExpFlags flags) {
32573262
RegExpMacroAssembler* macro_assembler = compiler->macro_assembler();
32583263
// Here we have special handling for greedy loops containing only text nodes
32593264
// and other simple nodes. We call these fixed length loops. These are
@@ -3280,7 +3285,7 @@ Trace* ChoiceNode::EmitFixedLengthLoop(
32803285

32813286
// In a fixed length loop there is only one other choice, which is what
32823287
// comes after the greedy quantifer. Try to match that now.
3283-
EmitChoices(compiler, alt_gens, 1, new_trace, preload);
3288+
EmitChoices(compiler, alt_gens, 1, new_trace, preload, flags);
32843289

32853290
fixed_length_loop_state->BindStepBackwardsLabel(macro_assembler);
32863291
// If we have unwound to the bottom then backtrack.
@@ -3340,7 +3345,7 @@ int ChoiceNode::EmitOptimizedUnanchoredSearch(RegExpCompiler* compiler,
33403345
void ChoiceNode::EmitChoices(RegExpCompiler* compiler,
33413346
AlternativeGenerationList* alt_gens,
33423347
int first_choice, Trace* trace,
3343-
PreloadState* preload) {
3348+
PreloadState* preload, RegExpFlags flags) {
33443349
RegExpMacroAssembler* macro_assembler = compiler->macro_assembler();
33453350
SetUpPreLoad(compiler, trace, preload);
33463351

@@ -3351,6 +3356,7 @@ void ChoiceNode::EmitChoices(RegExpCompiler* compiler,
33513356
int new_flush_budget = trace->flush_budget() / choice_count;
33523357

33533358
for (int i = first_choice; i < choice_count; i++) {
3359+
compiler->set_flags(flags);
33543360
bool is_last = i == choice_count - 1;
33553361
bool fall_through_on_failure = !is_last;
33563362
GuardedAlternative alternative = alternatives_->at(i);

deps/v8/src/regexp/regexp-nodes.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -709,10 +709,10 @@ class ChoiceNode : public RegExpNode {
709709
AlternativeGenerationList* alt_gens,
710710
PreloadState* preloads,
711711
FixedLengthLoopState* fixed_length_loop_state,
712-
int text_length);
712+
int text_length, RegExpFlags flags);
713713
void EmitChoices(RegExpCompiler* compiler,
714714
AlternativeGenerationList* alt_gens, int first_choice,
715-
Trace* trace, PreloadState* preloads);
715+
Trace* trace, PreloadState* preloads, RegExpFlags flags);
716716

717717
// If true, this node is never checked at the start of the input.
718718
// Allows a new trace to start with at_start() set to false.

deps/v8/test/mjsunit/harmony/regexp-modifiers.js renamed to deps/v8/test/mjsunit/regexp-modifiers.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,11 @@ test(/F(?i:oo(?-i:b)a)r/, ['Foobar', 'FoObAr'], ['FooBar', 'FoobaR']);
5151
test(/F(?i:oo(?i:b)a)r/, ['Foobar', 'FoObAr', 'FOOBAr'], ['FoobaR']);
5252
test(/^[a-z](?-i:[a-z])$/i, ['ab', 'Ab'], ['aB']);
5353
test(/^(?i:[a-z])[a-z]$/, ['ab', 'Ab'], ['aB']);
54+
test(/(?i:foo|bar)/, ['FOO', 'FOo', 'Foo', 'fOO', 'BAR', 'BAr', 'Bar', 'bAR']);
55+
test(/(?i:foo|bar|baz)/, [
56+
'FOO', 'FOo', 'Foo', 'fOO', 'BAR', 'BAr', 'Bar', 'bAR', 'BAZ', 'BAz', 'Baz',
57+
'bAZ'
58+
]);
5459
test(
5560
/Foo(?i:B[\q{ĀĂĄ|AaA}--\q{āăą}])r/v, ['FooBaaar', 'FoobAAAr'],
5661
['FooBĀĂĄr', 'FooBaaaR']);

0 commit comments

Comments
 (0)