[all-commits] [llvm/llvm-project] bb5e26: [Support] Fix alternation support in backreference...

Nikita Popov via All-commits all-commits at lists.llvm.org
Tue Jan 17 00:58:26 PST 2023


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: bb5e26dad9512e5d60a0462edf0d07044d21e22e
      https://github.com/llvm/llvm-project/commit/bb5e26dad9512e5d60a0462edf0d07044d21e22e
  Author: Nikita Popov <npopov at redhat.com>
  Date:   2023-01-17 (Tue, 17 Jan 2023)

  Changed paths:
    M llvm/lib/Support/regengine.inc
    M llvm/unittests/Support/RegexTest.cpp

  Log Message:
  -----------
  [Support] Fix alternation support in backreferences (PR60073)

backref() always performs a full match on the remaining string,
and as such also needs to be matched against the whole remaining
strip. For alternations, the match was performed against just the
sub-strip for one alternative, which would of course fail to match
the whole string.

This can be done by skipping the part of the strip between OOR1
and O_CH, so that only the first alternative in the strip is
matched, and the remaining ones are skipped. Indeed, the necessary
OOR1 skipping code was already implemented in the easy-path of
backref(), so this is clearly how it was supposed to work.

However, there were two bugs: First, under this scheme we should
be passing the stop point of the original strip, not just the
alternative sub-strip. Second, while skipping for OOR1 was
implemented, handling for O_CH was missing. This would occur when
the last alternative matches, as O_CH is preceded by an implicit
OOR1 only.

Fixes https://github.com/llvm/llvm-project/issues/60073.




More information about the All-commits mailing list