deps: V8: cherry-pick 72b0e27bd936 · nodejs/node@c361a62 · GitHub
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

4 files changed

Lines changed: 19 additions & 8 deletions

File tree

common.gypi

Lines changed: 1 addition & 1 deletion

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

0 commit comments

Comments
 (0)