Skip to content

Resume std::regex searches on libc++ without its ^ at the range start, and name the legacy-anchor cases libc++ cannot parse in the native unit - #12

Closed
puskuruk wants to merge 2 commits into
mainfrom
fix/libcxx-resumed-search-anchors
Closed

puskuruk wants to merge 2 commits into
mainfrom
fix/libcxx-resumed-search-anchors

Conversation

@puskuruk

Copy link
Copy Markdown
Collaborator

Two regex failures on macOS (Apple clang 21, libc++ 210106) that exist on main: test/runtime/regexp-anchors-line-terminators.ts and the native unit regexp-legacy-anchors-runtime. CI runs on Ubuntu, where neither shows.

^ at a resumed search. libc++'s basic_regex::__search clears match_not_bol whenever match_prev_avail is set, and its ^ accepts the first position of any search range outright, so a search resumed at lastIndex matched ^ there after any code unit: 'aa\na'.match(/^a/g) found two matches, 'a\nb'.replace(/^|$/g, '<>') gave <>a<>\n<>b<>, a sticky /^a/y at 2 matched in x\na. libstdc++ honours the flag. The runtime now resumes through Pattern::searchFrom: on libc++ a pattern with a ^ outside a class is searched in a caret-free form (each such ^ replaced by [^\s\S]) wherever no ^ can hold, and in its own form only from a position where one can -- position 0, or after a line terminator with m. Every other library takes the plain call it took before. The three resumed searches (exec, split, and the legacy path's unrewritten form) go through it.

The native unit. The rewrite a library without multiline needs checks a ^ reached after consuming with (?=\1). libc++ parses a lookahead as a pattern of its own, so a back reference to an outer group inside one is rejected, and the unit, which simulates that library by compiling every pattern multiline, aborted on a\n^b. libc++ has multiline and never takes the rewrite outside the simulation; the unit now names the cases that need that form and leaves them out on libc++ (14 of 87), running the rest.

Verified on this Mac: scripts/check-runtime-header.mjs passes; all 18 regexp* runtime programs pass including the one above; the native unit passes 73 of 87 with 14 named; npm run gate reports 0 drift. Verified in the Linux (libstdc++) container: the same 18 programs pass, and the unit passes all 87 cases (built without sanitizers there, the container has no ASan runtime for clang 18).

…: the pattern's caret-free form answers wherever no ^ can hold, its own form only from a position where one can
…side a lookahead, which libc++ rejects, out of the native unit on libc++, each named
@coderabbitai

coderabbitai Bot commented Oct 19, 2026 •

Copy link
Copy Markdown

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 59 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

⚙️ Run configuration
  • Configuration used: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 261cbc2f-09d1-4071-beed-71737ab3725d
📥 Commits

Reviewing files that changed from the base of the PR and between f9154e8 and eac5323.

📒 Files selected for processing: 2
  • src/targets/cpp/runtime/gea_runtime.h
  • test/runtime/regexp-legacy-anchors-runtime.cpp
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@puskuruk

Copy link
Copy Markdown
Collaborator Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Oct 20, 2026 •

Copy link
Copy Markdown
⚠️ Action not completed

Review rate limited.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@puskuruk

Copy link
Copy Markdown
Collaborator Author

Superseded by c0abb2d ("Resume regex searches correctly on libc++", released in 1.0.40), which fixes the same libc++ ^ resume at lastIndex through the search flags. On 1.0.41 check-runtime-header passes on macOS without this branch, so closing.

@puskuruk puskuruk closed this Oct 20, 2026
@github-actions github-actions Bot locked and limited conversation to collaborators Oct 20, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant