Commit 23bb940
committed
[JSC] RegExpExecNonGlobalOrSticky should have NodeMustGenerate to prevent DCE
DFGStrengthReductionPhase converts RegExpExec to RegExpExecNonGlobalOrSticky
when the regexp is a constant without the global or sticky flag. This
conversion calls setOpAndDefaultFlags(RegExpExecNonGlobalOrSticky) which
resets flags to the default, and RegExpExecNonGlobalOrSticky was missing
NodeMustGenerate.
DFGClobberize.h correctly declares write(RegExpState) for this node (it
shares the same case block as RegExpMatchFastGlobal). When the exec result
is unused, DCE eliminates the node and RegExp.lastMatch/$1/etc. are left
stale from a prior match:
function test(s) { /bc/.exec(s); } // result unused
/seed/.test("seeded");
test("abcd");
RegExp.lastMatch; // DFG/FTL: "seed" (stale), expected: "bc"
This is the same bug pattern as RegExpMatchFastGlobal, which was fixed in
309271@main (https://bugs.webkit.org/show_bug.cgi?id=309953). Both nodes
share the same Clobberize case block and the same conversion pattern in
DFGNode.cpp (convertToRegExpExecNonGlobalOrStickyWithoutChecks and
convertToRegExpMatchFastGlobalWithoutChecks both call setOpAndDefaultFlags).
RegExpExec (the source op) already has NodeMustGenerate. Adding it to
RegExpExecNonGlobalOrSticky makes DFG/FTL behavior match lower tiers.
Test: JSTests/stress/regexp-exec-non-global-or-sticky-dce-lastmatch.js
* JSTests/stress/regexp-exec-non-global-or-sticky-dce-lastmatch.js: Added.
(shouldBe):
(test):
(testCapture):
(testLeftRight):
(testNoMatch):
* Source/JavaScriptCore/dfg/DFGNodeType.h:1 parent 7da058f commit 23bb940
2 files changed
Lines changed: 61 additions & 1 deletion
File tree
- JSTests/stress
- Source/JavaScriptCore/dfg
Lines changed: 60 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
349 | 349 | | |
350 | 350 | | |
351 | 351 | | |
352 | | - | |
| 352 | + | |
353 | 353 | | |
354 | 354 | | |
355 | 355 | | |
| |||
0 commit comments